Geri
Junior Member
- Total Posts : 107
- Reward points : 0
- Joined: 2005/06/30 01:06:49
- Location: Austria
- Status: offline
Mismatched receive data using UART on dsPIC33CH512MP505
Hello together I have a simple UART program, generated with code configurator. Test program receives data and sends same data back to transceiver. My ProblemIf two or more bytes are sent from PC to the dsPIC33 at the same time, the receive data are mismatched. Device settingsInternal oscillator Baud rate 9600 bits/s I checkedData directly on Rx input pin are good (with oscilloscope) Signal shapes look fine I wrote a test program that writes 4 characters at the same time continuously form dsPIC33 to PC. All data are fine. So the transceiver should work correctly. Tested on two different IOs and UART1 and UART2. Same situation Tested with two different RS232 transceivers (Silicon labs) and ESP32 controller. Same situation. If I send on byte per second, the program works fine. If I send e.g. 0xAA 0xAB the dsPIC receives data 0xAA 0xF5 (see attached picture). The program uses input buffers with Rx and Tx-Interrupt but the problem also occurs if polling is configured in code generator. Testes input data with ICD4 debugger. Data mismatched Thank you for your help Geri
|
RISC
Super Member
- Total Posts : 5907
- Reward points : 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 13:30:50
(permalink)
Hi, How did you setup the oscillator ? internal / external ? What is Fosc in your system ? did yu compute the error on the baud rate ? Can you attach you zipped project ? Regards
|
Geri
Junior Member
- Total Posts : 107
- Reward points : 0
- Joined: 2005/06/30 01:06:49
- Location: Austria
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 13:48:50
(permalink)
Hello "How did you setup the oscillator ? internal / external ?"internal oscillator What is Fosc in your system ?8 MHzplease see attached picture. You can also see the PLL-Settings in the attached picture before did yu compute the error on the baud rate ? Baud rate error is 0,006% Can you attach you zipped project? I was not able to upload it here. I can only uploads pictures, no zip file -sorry Best regards and thank you Geri
post edited by Geri - 2020/05/13 14:02:54
|
du00000001
Just Some Member
- Total Posts : 4071
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 16:56:30
(permalink)
I'm not sure where an 0xAA 0xF5 might stem from. But I'm quite sure the first scope plot shows 0xAA 0x75 !!! (The latter shouldn't result in 0xAA 0xF5 other than with an instable clock with short-time jitter.) Looks like you maybe should check the transitting side as I cannot see your "e.g. 0xAA 0xAB".
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
RISC
Super Member
- Total Posts : 5907
- Reward points : 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 17:00:17
(permalink)
Hi, It is possible to upload many types of files but first push "Open full version" just above. I don't think you use Fosc = 8MHz....unless you did not activate the PLL. 8MHz is the internal oscillator frequence Frc This device can run Fcy = @90MIPS i.e. Fosc = 180MHz. It is not so simple to setup oscillator registers...I used MCC a couple of weeks ago to generate the code to achieve Fosc = 180MHz with dsPIC33CH512MP508. My setup is shown on the attached image Regards
Attached Image(s)
|
LdB_ECM
Super Member
- Total Posts : 456
- Reward points : 0
- Joined: 2019/04/16 22:01:25
- Location: 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 18:33:10
(permalink)
@ du00000001It is most definitely being sent 0xAA, 0xAB here I have marked the bits on the scope image
Attached Image(s)
|
LdB_ECM
Super Member
- Total Posts : 456
- Reward points : 0
- Joined: 2019/04/16 22:01:25
- Location: 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 18:40:30
(permalink)
Oh as for what is wrong my guess is the transmitter is 1 stop bit the receiver 2 ... which is why the second character is wrong :-)
|
du00000001
Just Some Member
- Total Posts : 4071
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 18:43:39
(permalink)
For me the two subsequent ones left to the cursors looked more like three ones in the first post. Might have been an error of assessment as the cursors somewhat hinder assessing the width of the other 1-1 sequence. BTW: Where did you hook up the scope? Receiving side? Including the ground clip?
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
ric
Super Member
- Total Posts : 29435
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: online
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 18:47:27
(permalink)
Maybe the PIC is configured for two stop bits. What value has been written to the UxMODEH register?
To get a useful answer, always state which PIC you are using!
|
LdB_ECM
Super Member
- Total Posts : 456
- Reward points : 0
- Joined: 2019/04/16 22:01:25
- Location: 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 18:48:58
(permalink)
I am fairly certain it's just a stop bit problem if he just spaces the characters out with a slight delay or change the sender to 2 stop bits I am sure it will work. The issue is the sender is definitely 1 stop bit and the characters are hard against each other which is why the wrong stop bit will cause problems.
|
du00000001
Just Some Member
- Total Posts : 4071
- Reward points : 0
- Joined: 2016/05/03 13:52:42
- Location: Germany
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 18:53:36
(permalink)
Checked the errata: might really be a stop bit problem as there's an error that won't raise an FERR (due to the 2-stop violation). Re-reading the scope with this assumption makes or a perfect 0xAA 0xF5. Sending some more characters without pause would unveil more "weird things". Writing appropriate characters could even raise FERR.
PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
|
ric
Super Member
- Total Posts : 29435
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: online
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/13 18:58:09
(permalink)
Quickest solution, change the PC to transmit 2 stop bits.
To get a useful answer, always state which PIC you are using!
|
Geri
Junior Member
- Total Posts : 107
- Reward points : 0
- Joined: 2005/06/30 01:06:49
- Location: Austria
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/14 00:24:37
(permalink)
Good morning together Thank you all for your help. I tried your hint with the two stop bits and now the program is working. So for all having similar problem, a change to 2 stop bits could helps. However, I checked the UART settings and it should be OK. I attached a screen shot of the UART init procedure. The example code was fully be created using the MC code configurator. I again tried to upload the full project for your information but I still can only upload gif, txt, jpga are supported. What I am doing wrong? @du00000001: Regarding the errata sheet: I studied the document but as I saw, a problem should only occur if:? 6. Module: UART When the UART is operating with STSEL<1:0> = 2 (two Stop bits sent, two checked at receive) and STPMD = 0, the FERR bit will not get set if one Stop bit is received.
http://ww1.microchip.com/downloads/en/DeviceDoc/dsPIC33CH512MP508-Family-Silicon-Errata-and-Data-Sheet-Clarification-DS80000805D.pdf Thank you Geri
|
RISC
Super Member
- Total Posts : 5907
- Reward points : 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/14 04:42:47
(permalink)
Hi, To upload a zipped project, just rename it xxxx.zip.txt (if you zip is to big, just delete the directories build, debug and dist from your project (no NOT delete nbproject which contains the project configuration) Regards
post edited by RISC - 2020/05/14 04:45:50
|
Geri
Junior Member
- Total Posts : 107
- Reward points : 0
- Joined: 2005/06/30 01:06:49
- Location: Austria
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/14 05:05:56
(permalink)
Hello Thank you Risc. Attached the zipped MPLAB-project Best regards Geri
|
JPortici
Super Member
- Total Posts : 1241
- Reward points : 0
- Joined: 2012/11/17 06:27:45
- Location: Grappaland
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/14 06:01:02
(permalink)
Unsurprisingly, the dspic33CK seems to be affected too. More data will follow if i can confirm, but i'll leave you with this: I don't think it's a coincidence that this was left in the peripheral STSEL[1:0]: Number of Stop Bits Selection bits 11 = 2 Stop bits sent, 1 checked at receive 10 = 2 Stop bits sent, 2 checked at receive 01 = 1.5 Stop bits sent, 1.5 checked at receive 00 = 1 Stop bit sent, 1 checked at receive Or at least, it's the first time i've encountered all these combinations of start/stop bits in microchip parts I read of a recent errata for another part (which i can't remember) that it was checking/sending half a bit less for the stop bit
|
Gort2015
Klaatu Barada Nikto
- Total Posts : 4014
- Reward points : 0
- Joined: 2015/04/30 10:49:57
- Location: 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/14 15:37:11
(permalink)
256K, 7 x data, 1 x stop, xon. Running 2 x uarts (next to I2C) btss U1STAH, #UTXBE bra $-2 mov ch, U1TXREG Instead of checking when full, check when empty. (sending) A 100nF near the power pins for each uart will keep it stable all Day @256K. Configure uart with fraction divide.
post edited by Gort2015 - 2020/05/14 15:39:12
|
Geri
Junior Member
- Total Posts : 107
- Reward points : 0
- Joined: 2005/06/30 01:06:49
- Location: Austria
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/15 05:28:42
(permalink)
Hello It it seems that the problem still exist, also with two stop bits. I checked UART1 and UART2 on two different IO pins => same problem Baud rates 2400 baud, 2 stop bits, 115200 2 stop bits 0 => same problem Total code has been generated by MCC I checked the receive data directly at the input pin of the dsPIC33 with my oscilloscope => all data are OK Please see attached pictures. A also attached the project. In my tests, it was always only one bit that changed randomly. @GORT2015: it is a problem of receiving data. Transmitting data with the dsPIC works fine. Best regards Geri
post edited by Geri - 2020/05/15 05:36:25
|
ric
Super Member
- Total Posts : 29435
- Reward points : 0
- Joined: 2003/11/07 12:41:26
- Location: Australia, Melbourne
- Status: online
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/15 05:36:36
(permalink)
Set the PIC to receive 1 stop bit, and the PC to send 2.
To get a useful answer, always state which PIC you are using!
|
Gort2015
Klaatu Barada Nikto
- Total Posts : 4014
- Reward points : 0
- Joined: 2015/04/30 10:49:57
- Location: 0
- Status: offline
Re: Mismatched receive data using UART on dsPIC33CH512MP505
2020/05/15 06:22:55
(permalink)
Did you try fraction divide for uart setup? Important for fast fcy. I'm using breadboards with 13cm fly leads. Power supply stable? This is the core: btss U1STAH, #UTXBE bra $-2 mov ch, U1TXREG I check for empty rather than full due to the errata. Checking for UTXBF does not work and repeated chars will appear. You have to try it to see the bug then you have verified it. RX works with interrupts.
|