News:

;) This forum is the property of Proton software developers

Main Menu

Simple Serial Comms issue

Started by Peter Truman, Jul 27, 2024, 07:53 AM

Previous topic - Next topic

Peter Truman

Hi All

Kicking myself for having to ask for help with this but....

I'm writing a short routine to handle a serial transaction between the PIC and the PC
I'm using the RSIN command (because there is no MAX232 on this board so data is inverted therefore I can't easily use a serial interrupt / serial buffer)

Basically I want to sit in a loop looking for a particular string from the PC (say "ABC") - once I see that string I want to respond with say "DEF"

I can receive data from the serial port with no problem but...

Looking in the manual (pg 232) - I think I should be able to use

Rsin Wait("XYZ"), SerData (obvs changed to Rsin Wait("ABC"), SerData

I've not been able to make this work!

Here is my setup
Compiler 1.0.3.2

This is my serial port setup
Declare RSOut_Pin PORTC.6
Declare RSIn_Pin PORTC.7
Declare RSIn_Timeout=10000
Declare Serial_Baud 14400
Declare RSOut_Mode inverted
Declare RSIn_Mode inverted

test_area:
Dim B_General as byte
T1CON.0=0             
RsOut "Waiting",13,10
Clear B_General
While B_General<>13
    RsIn Wait("ABC"),B_General                                  'exit gracefully
    RsOut Dec3 B_General
Wend
RsOut "Out of loop",13,10

I can't see any reason this won't work? I know I have the expected data on the relevant lines (logic analyser)

I did spend several hours this arvo trying to figure out how I can convert an ascii input into a text chr to append to a string - I think I mut be missing something obvious, I'd like to understand why these example don't work?

another_test:
Dim S_String As String * 3
Clear
While S_String<>"ABC"
    RsIn Str B_General
    S_String=S_String+B_General   
Wend
RsOut "Out of loop",13,10

third_test:
Dim S_1chr As String *1
Dim S_String As String * 3
Clear
While S_String<>"ABC"
    RsIn S_1chr
    S_String=S_String+S_1chr   
Wend
RsOut "Out of loop",13,10


While 1=1
    RsIn B_General
    RsOut Dec3 B_General,13
Wend

works fine so I don't think it is any kind of hardware issue

Can anyone offer any suggestions? (I will need to timeout if I don't see the "ABC" - not 100% sure the Wait command will do that? (I have 10 seconds set as the timeout)

Many thanks in advance



RGV250

#1
Hi,
Having a quick glance at the manual I was a little confused (easily done) if it only worked with numeric values or you have to use ASCII equivalent so have you tried 123 etc. I also wondered if adding another character would help as there, I am not sure if the return is what it needs?

Have you looked at Rsin1 /2 in the SerialIn samples folder?

Bob

Peter Truman

Hmmn. would love to have a look in the samples - but I can't find them! Not looked in there for years and this is a new PC, could you point me at where they may be located?

Don't seem to be in ProgramData/Positron Studio or Programfiles(x86)/ProtonIDE/PDS (or anywhere else in there)

Thanks
Peter

 

Peter Truman

Ok - sorted.

The problem was, I'm running this PIC at 4MHz and I had the board rate set at 14400 - this seems to be fine for Rsout, but is unreliable for Rsin

I changed the baud rate to 9600 and now it works as expected.

The fact that Rsout worked ok made me complacent about the speed.

I'll change my config to run at 8MHz and hope that fixes the issue.

While not exactly a 'new player' I generally have a Max232 chip on my boards and use the hardware interrupts for serial work - this was certainly a trap for me! :(

RGV250

Hi,
Glad it is sorted, as for the samples. If you have not changed anything when you select "file, Open" it takes you to the PDS folder where samples and samples24 are.
If that does not work, mine are located at..
C:\Users\User Name\PDS\Samples

Bob