Formatted strings in C code generate (by Alessandro)
Firstly thanks for shared this code to others...
I trying to change the C source code generator to support the send of strings over serial line.
The resulting C code send the characters over serial line but i receive always zeros. In the simulate or PIC code generator the same format string works fine, so i think something is missing in the C code version in to work fine.
See attached my version of ansic.cpp, line 364.
Thanks.
(no subject) (by Jonathan Westhues)
Why do you write the character I_scratch2?
The INT_UART_SEND op accepts an integer input variable, IntCode[i].name1, which contains the character to be sent, and a bit variable, IntCode[i].name2.
If the bit variable is true, then the character will be sent. If not, then the instruction is a no-op. On return, the integer variable is unchanged, and the bit variable is true if the UART is busy, and false if it is ready to accept a new character.
(no subject) (by Alessandro)
Ok, as his explanation i change the code to:
case INT_UART_SEND:
fprintf(f, "%s = RS232Write(%s);\n", MapSym(IntCode[i].name2), MapSym(IntCode[i].name1));
break;
RS232Write always return false (never busy) because wait character will be send. This is possible because cycle time is slow enough (10ms) to send 1 character at 115200:
unsigned int RS232Write(unsigned int c)
{
while (!(UART0->LSR & 0x20) ); /* THRE status, contain valid data */
UART0->THR = (char)c;
while (!(UART0->LSR & 0x20) );
return 0;
}
The resulting in serial line is:
\0x003\0x00=\0x00=\0x00=\0x00=\0x00
\0x00\0x00
\0x00
\0x003\0x00=\0x00=\0x00=\0x00=\0x00
\0x00\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x00
\0x003\0x00=
\0x00=\0x00=\0x00=\0x00
\0x00\0x00
The PIC or the simulator has some control variables that I did not understand exactly how they work, is this missing some variable control here too.
I check the baudrate sending a plain text bypass C source code and it's ok.
Please, see attached ld.c generated.
Thank you very much.
uart communication (by maximus)
can any body give me sample program for uart communication for more of 4 avr ,,,? like modbus master and slave...?
please......