Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 01:43 28 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Picomite Serial Comm

Author Message
Bill.b

Senior Member

Joined: 25/06/2011
Location: Australia
Posts: 225
Posted: 03:11am 14 Mar 2024
Copy link to clipboard 
Print this post

I am trying to send data to a DPplayer MP3 module.  The module is working OK when activated by a push button but does not respond to the serial comms input
I have used this module with picaxe in the past with great success

This is the picaxe coms used to send data the DPplayer.

SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )

Thepico program is

Option colourcode on
Option autorun on
Option DEFAULT NONE

dim integer CMD1,arg2

cmd1 = &h09   'Set SD card
arg2 = 0002
send
cmd1 = &h06  'Set volume
arg2 = 40
send
Do
cmd1 = &h12  'Play 0001.mp3
arg2 = 1
send
pause 1000
cmd1 = &h12  ' 'Play 0002.mp3
arg2 = 2
send
pause 1000
cmd1 = &h12   'Play 0003.mp3
send
pause 1000
loop

sub send
SetPin GP21, Gp20, com2
Open "com2:9600" As  #2
print #2,&h7E,&hFF,&h06,cmd1,&h00,00,arg2,&hEF
pause 100
arg2 = 0
close #2
end sub


Need help with the comms.

Bill
Edited 2024-03-14 13:12 by Bill.b
In the interests of the environment, this post has been constructed entirely from recycled electrons.
 
PhenixRising
Senior Member

Joined: 07/11/2023
Location: United Kingdom
Posts: 284
Posted: 03:30am 14 Mar 2024
Copy link to clipboard 
Print this post

Suggest you start with bin2str (manual)

I use it a lot, along with str2bin  
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 03:42am 14 Mar 2024
Copy link to clipboard 
Print this post

At first glance there are a few things that don't look right.  For a start, the commas in the PRINT statement will insert tab characters or spaces in the output which I doubt that you want.  Secondly, a constant like &h7E will be converted to a decimal number by the PRINT command which is not what you want.  Thirdly, you should add a semicolon at the end of the PRINT command to tell MMBasic to not append a CR/LF pair.

My guess is that you need something like this:
print #2, Chr$(&h7E) + Chr$(&hFF) + Chr$(&h06) + Chr$(cmd1) + Chr$(0) + Chr$(arg2) + Chr$(&hEF);

Also, why keep opening and closing the serial port?  It probably is not causing any trouble but normally you would leave it open while the program was running.

Geoff
Edited 2024-03-14 13:49 by Geoffg
Geoff Graham - http://geoffg.net
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1783
Posted: 03:47am 14 Mar 2024
Copy link to clipboard 
Print this post

Is there a particular need to Open and Close COM2 in the Sub?
I usually set the pins and Open at the start of the program and Close at the end.

If it must be done in the Sub perhaps put a 30mS pause between Open and Print to ensure it is ready to take the data.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1593
Posted: 03:50am 14 Mar 2024
Copy link to clipboard 
Print this post

You need to convert the data to 8 bit ascii characters using the CHR$() function.

Try:
sub send
SetPin GP21, Gp20, com2
Open "com2:9600" As  #2
' print #2,&h7E,&hFF,&h06,cmd1,&h00,00,arg2,&hEF
print #2,chr$(&h7E),chr$(&hFF),chr$(&h06),chr$(cmd1),chr$(&h00),chr$(00),chr$(arg2),chr$(&hEF)
pause 100
arg2 = 0
close #2
end sub


Bill
Edited 2024-03-14 13:51 by Turbo46
Keep safe. Live long and prosper.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 05:03am 14 Mar 2024
Copy link to clipboard 
Print this post

  Turbo46 said  print #2,chr$(&h7E),chr$(&hFF),chr$(&h06),chr$(cmd1),chr$(&h00),chr$(00),chr$(arg2),chr$(&hEF)

No Bill, the commas (,) in the PRINT command will insert tabs or spaces.  Not what is intended.

My replacement PRINT command (above) was missing one character on the output.
I believe that this is what is required:
print #2, Chr$(&h7E) + Chr$(&hFF) + Chr$(&h06) + Chr$(cmd1) + Chr$(0) + Chr$(0) + Chr$(arg2) + Chr$(&hEF);

Geoff
Edited 2024-03-14 15:04 by Geoffg
Geoff Graham - http://geoffg.net
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1593
Posted: 05:25am 14 Mar 2024
Copy link to clipboard 
Print this post

Of course. thanks.    I should have checked against some of my work.

I normally assemble the message first.

Txd$ = Chr$(&h7E) + Chr$(&hFF) + Chr$(&h06) + Chr$(cmd1) + Chr$(0) + Chr$(0) + Chr$(arg2) + Chr$(&hEF)
print #2 Txd$;

The semicolon suppresses the CR/LF

Bill
Keep safe. Live long and prosper.
 
Bill.b

Senior Member

Joined: 25/06/2011
Location: Australia
Posts: 225
Posted: 09:07am 14 Mar 2024
Copy link to clipboard 
Print this post

Thank Geoff

Working OK now.

I closed the comms port as this is part of a program with an other comm port for a bluetooth HC-06 is included in the full program.

Bill
In the interests of the environment, this post has been constructed entirely from recycled electrons.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024