|
I don't know if this is a bug of the PIC's hardware UART or in the Atom BASIC compiler or some combo.
I wanted to test some devices at work with one of ELProduct's OEM Atom Module development system boards. I wanted to do long term power-on tests where a string of ASCII characters go through a chain of devices one way, then the same string gets sent the other way. Since there is at most a few microseconds delay from the transmit pin to the receiving pin I couldn't use a software bit-bang serial port. I had to use the internal UART with it's ability to just snag incoming characters and stuff them into a buffer without intervention on the processor's part. The heart of the code is:
After initializing the hardware UART to work at 19200 Baud, we do FOR X = 33 TO 122 'all recognizable ASCII character values CHAR = X 'assign an ASCII character to the transmitted character HSEROUT [CHAR] 'send the character out HSERIN [CHAR_RCV] 'get the character in using a different variable SEROUT s_out, I57600, [DEC CHAR, " ", DEC CHAR_RCV, " "] 'display characters out/in in terminal display IF CHAR_RCV <> CHAR THEN _Err_Report NEXT 'Do 90 characters
This sits in a MAIN routine which contains other support code and is looped back to continuously. After this series finishes, direction of flow is reversed and then we do this all over again.
So, on the display, we EXPECT to see a string of ASCII characters (two of each) marching across the screen, over and over. What we get is an immediate error that shows the original character, something totally different from the original, and the error message showing these characters again and a blinking red LED. No amount of carefully spaced, constantly increased, pauses will fix this situation. First character out - and - BAM!
So, I simplify and troubleshoot. What about one value? Send out Hex55 (digital technicians will know why this value was chosen). An o-scope trace shows the proper voltage levels, in the sequence expected, in the proper pulse widths. But, after turning off error reporting, the terminal display shows the first 26 characters received back to the UART don't match the Hex55 out. Consistently. In fact most are zero?! But after that the results are good. I suspect that the hardware being tested is contributing to this phenomena. So a 'pump priming' loop is run first, THEN we run a loop where the error report is turned on. Only to find that THAT first loop fails somewhere in the 20 characters, but not usually the first character. So another IF conditional is added that skips the error detection for the first loop. After that everything works as expected. Now some other key Hex values (0, FF, and AA) are tried, by themselves, with no problems. So, it's time to try ASCII again.
A short FOR - NEXT loop, 33 TO 42, is tried. Once again it fails. But the results are recognizable ASCII values, consistent and perhaps indicative of the nature of the problem. Unfortunately I never recorded the results so I can't repeat them here exactly. But the strings were the same, even the characters in error.
Eventually I settled on a string of alternating 55/AA/55/AA/... This suffices for now. I dropped all the pauses and upped the transmission speed to 57600. Everything runs fine - if I limit the chain to four devices.
After reading the latest Atom manual and Chuck's Atom book I have no idea where the problem comes from. Comments? Ideas? Suggestions? I would REALLY like to stress test this equipment and a full ASCII string would be best here for my purposes.
Later! kenjj
|