View previous topic :: View next topic |
Author |
Message |
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
Question about UART transmission |
Posted: Wed Oct 13, 2004 3:09 am |
|
|
Hi everybody!
I have a simple question regards the UART interface with CCS Compiler : is it possible to send a simple byte like 0x2C on the serial port, which is not an ASCII character ?
Thanks for your support |
|
|
dvsoft
Joined: 28 Nov 2003 Posts: 46
|
|
Posted: Wed Oct 13, 2004 3:41 am |
|
|
bonjour
yes completely why?
Alain |
|
|
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Wed Oct 13, 2004 3:52 am |
|
|
Coucou
Ok I have to send 0x0001C8C8 to a module with USART interface, but I'm not sure that my program will work, I'm going to test it in a few days.
Here is my code :
while(getc()!=0x10) {} // Attente du "Frame Char" pour se synchroniser
printf(lcd_putc,"\fSynchro OK!\n");
trame=getc(); // Lecture de la suite
if(trame=0x0001C8C8) output_high(LED0);
Thanks for the reply |
|
|
Ttelmah Guest
|
|
Posted: Wed Oct 13, 2004 4:07 am |
|
|
YulL wrote: | Coucou
Ok I have to send 0x0001C8C8 to a module with USART interface, but I'm not sure that my program will work, I'm going to test it in a few days.
Here is my code :
while(getc()!=0x10) {} // Attente du "Frame Char" pour se synchroniser
printf(lcd_putc,"\fSynchro OK!\n");
trame=getc(); // Lecture de la suite
if(trame=0x0001C8C8) output_high(LED0);
Thanks for the reply |
A _byte_. only holds 8bts of data. The serial link transfers data a byte at a time. What you need is something like:
Code: |
union dblock {
int32 word;
int8 b[4];
} buffer;
int 8 count;
while(getc()!=0x10);// Attente du "Frame Char" pour se synchroniser
printf(lcd_putc,"\fSynchro OK!\n");
for (count=0;count<4;count++) {
buffer.b[count]=getc(); // Lecture de la suite
}
if(buffer.word=0x0001C8C8L)
output_high(LED0);[/color]
|
You will have to check whether the data is send least significant byte first or last, and change the count to correspond. This reads the four successive bytes, into b[0]...b[4], and then performs a test with the resulting 32bit 'word'.
Best Wishes |
|
|
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Wed Oct 13, 2004 4:27 am |
|
|
Thanks for your help!
I will try it in a few days (I haven't the possibility to test it yet).
it is "if(buffer.word=0x0001C8C8) output_high(LED0);" and not "if(buffer.word=0x0001C8C8L) output_high(LED0);" ?
|
|
|
dvsoft
Joined: 28 Nov 2003 Posts: 46
|
|
Posted: Wed Oct 13, 2004 8:24 am |
|
|
bonjour,
ATTENTION
in C language the test operator is "=="
if (testValue == 0x0001C8C8)
output_high(LED0);
Alain |
|
|
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Wed Oct 13, 2004 8:40 am |
|
|
Thanks Alain, have a nice evening |
|
|
Ttelmah Guest
|
|
Posted: Wed Oct 13, 2004 10:48 am |
|
|
YulL wrote: | Thanks for your help!
I will try it in a few days (I haven't the possibility to test it yet).
it is "if(buffer.word=0x0001C8C8) output_high(LED0);" and not "if(buffer.word=0x0001C8C8L) output_high(LED0);" ?
|
'L', means force use of a 'long'. Though the compiler _should_ automatically detect that something 'larger' than 0xFF, needs a long comparison, I never trust it, and will always explicitly declare anything larger than 8bit, as a long.
Best Wishes |
|
|
|