UART - sendchar / sendnumber

Moderator: Benj

Post Reply
DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

UART - sendchar / sendnumber

Post by DCW »

Hello folks.... yeah - okay so I have become totally confused - BUT until I tried some other 'stuff' ... then I found stranger things...
In the UART component... one has SENDCHAR , and then SENDNUMBER ...

So now... in one program... what I would call a number generator... on another PIC chip... I have a simple loop, which transmits a number... it sends out - like to a terminal program... on the PC... it sends out... numbers like 7 and 8 and 9 and 10... and so on..
So you simply let an input go up to +5V.. and then depending which pin is taken up... the software then sends out the number... as I said like 7 or 8 or 9 or 10... okay...
So now I send that with the UART onto an RS232 line... and it pitches up into another UART... SOFTWARE... type UART...
So I tried the circular buffer idea... BUT could not get it to work...??? at all ... I dunno if this is because it's complicated SOFTWARE UART... story..???
So I changed the INTERRUPT idea... to IOC0 ... and set the correct UART to work with it...I also set properties to work with both rising and falling...pulses..
I then wrote the program... very simple, and which after doing all the initailizations... simply goes into an endless loop...
Inside the loop... we GETBYTE from the CIRCULAR BUFFER... setup in the steps above... then decide if it's 255 .. we go past the UART printout routine... otherwise... the program.. UARTs out to the terminal port.. on the PC...
SO now.. if I use PRINTCHAR ... I get... like 7, or 8, or 9 ... BUT NOT 10...!!!! I get L.. and some squiggle... character.. when I make it printout the 9... it comes out perfectly... USING THE PRINTCHAR.... setting... to output...
Okay so then when I change the program... edit it.. to output SENDNUMBER .. I get a 55 for the 7 ... 56 for the 8... and 57 for the 9... NOW the 10 comes out... as 49 then 48 ... or for 11... I get... 49 then 49 ...??...
So now .. I was really battling to get the routine to work... the decoding routine... BUT now in hindsight... I was being pathetic...AND STUPID.... I expect...!!!!

In the number generator program... I used the SENDNUMBER instruction.... AND I SHOULD HAVE USED THE .... SENDCHAR instruction....!!!

So after changing this ... re-compiling... and testing again.... the decoding routine... is now working correctly.... printing out DECIMAL numbers....using the SENDNUMBER instruction... to print out the values.... WOW ...
So I just thought I would add this here for all to see.... I think it's worth while...

What still confuses me... is that I cannot get the RXINT0 interrupt setting to work the CIRCULAR BUFFER.. but I expect it's all the wizardry of the SOFTWARE UART... that could be making things a bit hot in ..."the mix"... maybe Ben / Leigh could drop a comment...
BUT after changing to the IOC0 interrupt setting.. it seems to be working a real treat now...!!
I will test it to death... of course...!!!
I have also noticed that in the interrupt called macro... that the (.Data = UART1::ReceiveChar(0) ) .... I have set (0) to ... 255... wait forever...
maybe this is incorrect... BUT it seems to work... A-okay...so far....
regards to ALL..
Spencer..
P.S. this sudden ... moment... when win 10 takes over and creates mayhem.. and disaster... I have created that by opening - say 3 -4 totally new instances of flowcode... it seems that there something NOT LEKKER...there... cause that's how I do it -... everytime a coconut...!!!
bye...!!
Attachments
PIC16F1615-UART1-UART2-transfer-Flowcodev8.2.1.13.fcfx
just catch incoming numbers and reprint to PC teraterm
(15.16 KiB) Downloaded 148 times
PIC16F1824-UART-to-external-micro-transfer-FC8.2.1.13.msg.txt
the NUMBER GENERATOR program...
(2.02 KiB) Downloaded 157 times

DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

Re: UART - sendchar / sendnumber

Post by DCW »

HEY...!!!! what an idiot... sent the wrong file... DAMN it all...
here goes again....
Sorry for this...!!
chows...
Attachments
PIC16F1615-UART1-UART2-transfer-Flowcodev8.2.1.13.fcfx
(15.16 KiB) Downloaded 164 times

DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

Re: UART - sendchar / sendnumber

Post by DCW »

STILL the incorrect file....
bye..!!!
Attachments
PIC16F1824-UART-to-external-micro-transfer-FC8.2.1.13.fcfx
(23.73 KiB) Downloaded 162 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: UART - sendchar / sendnumber

Post by Benj »

Hi Spencer,

It sounds like this problem is because of the ASCII encoding.

When you sendchar it takes the bytes value as is and sends it, the program you are using the view the data is representing the bytes as ASCII so a '0' or decimal 48 is being shown as a '0' character.

When you sendnumber this converts the byte value into ASCII so sending '0' or 48 sends the ASCII characters '4' and '8'.

To print the number 10 you have to send two ASCII characters a '1' and a '0' and so cannot be send as a single byte.

By the way a character in quotes e.g. '0' is the ASCII for the number 0 and can be used in both C and Flowcode to enter ASCII characters. e.g. 'A' would be an ASCII A character which is 65 in decimal.

This should hopefully help to explain things.
http://www.asciitable.com/

The printnumber function is probably the one you want. Say X is 10 and you printnumber X then you should get the value 10 appearing on your terminal. If you are having to receive this with a micro then you are better off using sendchar and this way the receiver will receive the value 10. It's a bit confusing but once you get the hang of it it's not too bad.

What exactly are you trying to do and maybe we can offer a simpler way of acheiving it.

Post Reply