View previous topic :: View next topic |
Author |
Message |
rudy
Joined: 27 Apr 2008 Posts: 167
|
18F2550 UART END RECEPTION |
Posted: Thu Sep 07, 2023 6:35 pm |
|
|
Hi there,
Is there a way to detect if the UART received an end of transmission?
Regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Fri Sep 08, 2023 1:05 am |
|
|
Fundamentally no.
Depends what your system sends as a marker for this. If it is the EOT
character, then this is just a character, and your code will just need to test
if the received character matches this. It is just CTRL-D.
Understand the UART purely handles the physical transmission and reception
of characters. It doesn't do anything 'with' them. This is purely down
to your software. As far as it is concerned there is no difference between
numbers, alphabetics, line feeds etc. etc.. Handling each of these is down
to the receiving software. |
|
|
rudy
Joined: 27 Apr 2008 Posts: 167
|
|
Posted: Fri Sep 08, 2023 3:40 am |
|
|
So, I need to do the delimiters count, lets say, in the SIM800L there are three 0x0D and three 0X0A for each SMS received, and this is the only way I can say that the USART finished receiving?.
Thank you! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Sep 08, 2023 5:16 am |
|
|
just to add to Mr. T's reply...
Have a look at the 'timed serial receive' in the FAQ of the manual. It's really important to know when data doesn't come in (or the wire breaks..). If you know the 'data stream' consists of a fixed number bytes, it'll take a known amount of time,say 1.2 seconds. You set a timer to 1.4 seconds (usually 2-3 bytes more than the maximum data...). If the sending device fails or the wire breaks, the code will 'time out', set a flag,and you can abort the receive,clear the buffer, try again. Otherwise the PIC will sit in a loop forever waiting for those missing bytes.
Also you mention the SIM800l. That's a 3 volt device and will NOT directly connect to the 5 volt PIC ! Probably 99.44% of all external peripherals today are 3 volt devices, so best to choose the 'L' version of a PIC that will run at 3 volts or another PIC that runs at both 3 or 5 volts.Otherwise you need a 'logic level conversion' interface to get the PIC and SIM to talk to each other. Now that PIC may have an input that will accept the SIMs 3 volt output but not all pins ! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Fri Sep 08, 2023 5:20 am |
|
|
The UART never finishes receiving. It is listening all the time. You are
looking for the end of message, and this you have to decode for yourself.
No magic. It is called programming.
How SMS's are treated when received, depends on settings you make to
the chip. Normally The SMS messages are stored in the memory on the chip,
and you are sent a notification that one has arrived. You just send
a read 'unread' command, and read the data that comes back. The data has a
header saying what number it came from, then the date and time, then the
message itself, and OK at the end.
OK is the standard end marker for pretty much all modem communications.
Even when automatic forwarding is setup (so the message arrives directly),
it still has the OK terminator. |
|
|
rudy
Joined: 27 Apr 2008 Posts: 167
|
|
Posted: Fri Sep 08, 2023 9:03 am |
|
|
@temtronic, not really! The "SIM800L module" here works pretty well at 5V, no issues about that.
@Ttelmah that's is the case, we never know the length of the message. Regardless of I2C, when you have a clear I2CStart() and I2CStop(), I was wondering if there is a similar "function" over USART, but there is none. I was confusing (misunderstanding) with bit RCIF, but it only shows when the BYTE is putted on the USART buffer, and it is ready to be read.
No issues, I can handle it.
Regards; |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Fri Sep 08, 2023 9:27 am |
|
|
The key difference here is that I2C is a bidirectional bus. Therefore has to
have a protocol (immediately after the start) to reverse the bus.
So I2C has a bus based packet protocol. Serial using a UART does not.
The protocol becomes whatever the attached device(s) use. In this case
the AT command protocol, which uses OK as it's end marker.
Last edited by Ttelmah on Fri Sep 08, 2023 9:42 am; edited 1 time in total |
|
|
rudy
Joined: 27 Apr 2008 Posts: 167
|
|
Posted: Fri Sep 08, 2023 9:39 am |
|
|
I love I2C, but I am studding the USART, it is pretty easy, but it has some differences. No problem.
Thanks! |
|
|
|