CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

garbage data on usart

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

garbage data on usart
PostPosted: Mon Mar 19, 2007 8:46 am     Reply with quote

When I use a simple fprintf like :

fprintf(SW_UART,"S");
OR
fprintf(SW_UART,"%C%C%C%C%C%C%C",char1,char2,char3, etc);
it gets really bad garbled data

BUT if i use the command:
fprintf(SW_UART,"N/A,");

it prints that perfectly.

If i use longer delays the garbage data gets worse.

I am using max233 and this has never happened with the same code before. Only now when its in a pcb board and not on the breadboard I prototyped it to.

did i do something to my #use statement?
(software uart)

#use RS232(baud=2400,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=8,ERRORS,STREAM=SW_UART)

also: my bootloaded program times out first time (sends the garbage code)

but if I retry, it works 100% of the time and the code is correct
Ttelmah
Guest







PostPosted: Mon Mar 19, 2007 8:59 am     Reply with quote

'ERRORS', does nothing on a software UART.
You talk about 'delays'. If these are interrupt driven, then this is the problem. The software UART, requires nothing else to interrupt it's timings. It is possible to bodge round this, with code like:
Code:

void send_char_sw(int8 chr) {
   disable_interrupts(GLOBAL);
   fputc(chr,W_UART);
   enable_interrupts(GLOBAL);
}

//Then use this with
printf(send_char_sw,"Test message");

Depending on how 'late' your compiler is, there may be the option for the #USE RS232, of 'DISABLE_INTS', which does the same thing.
These approaches, allow interrupts to be serviced between the characters being sent.
At a low rate like 2400bps, it is possible to have interrupt routines called, provided these are kept really short, and the frequency is not too high. However this needs _care_.

Best Wishes
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Mon Mar 19, 2007 9:36 am     Reply with quote

ERRORS was added as a desperate last attempt Sad

the 'delays' are the delay_ms() command inbetween printf commands

not putting them in causes the code to be 'mostly correct' I.E. I can still see some good data being sent, but using delay_ms(500) then it causes ALL data to be garbage except for the "N/A," text.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group