[MC9S08] uart + RS485 problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[MC9S08] uart + RS485 problem

2,583 Views
Mishup
Contributor I
Hi everyone, i've been trying to set up communication between my board and laptop using sci, max481 and usb<->rs485 converter. I set in terminal, converter and component in PE like this: 9600 baud, none parity checking, one stop bit. I enabled interrupts from errors, tx and rx. Starting the program in debugger i checked that when data is received, RDRF bit is set (data is in SCIxD register), but immediately Interrupt on Error is requested and Framing Error bit is set. While this interrupt is being services also bit OR in SCIxS1 is set. Then all of them are cleared. And that's what happen all the time. I've got no idea what is going on. Maybe it must by done in other way, I not really familiar with CW an hc9s08 uCs. If any code or details needed, write please. I'd appreciate any help, Best regards Mishup
Labels (1)
Tags (1)
0 Kudos
Reply
6 Replies

781 Views
peg
Senior Contributor IV

Hello,

 

Are you using an internal clock source for your BUSCLK? and is it calibrated?

Baudrate misamtch is the most common cause of framing errors. The overrun could be becasue you are not handling the FE properly. Some code would be useful.

0 Kudos
Reply

781 Views
Mishup
Contributor I
I don't know if I understood You correctly. In CPU component I set High Speed Box on internal clock and Internal Bus Clock at 16 MHz. I don't see in SCI component (nor in registers) possibility to change clock for this module. This is how I handle interrupt errors: void uart_com_OnError(void) { led_ctrl_ClrBit(0); (void)SCI1S1; (void)SCI1D; } That's all. Anything else I configured with PE components library I am beginner in this stuff, so please be understanding. Mishup
0 Kudos
Reply

781 Views
Mishup
Contributor I

I don't know if I understood You correctly. In CPU component I set High Speed Box on internal clock and Internal Bus Clock at 16 MHz. I don't see in SCI component (nor in registers) possibility to change clock for this module.

This is how I handle interrupt errors:

void uart_com_OnError(void)

{

 led_ctrl_ClrBit(0);

(void)SCI1S1;

(void)SCI1D;

}

That's all. Anything else I configured with PE components library I am beginner in this stuff, so please be understanding.

 

Sorry for doubling.

 

Mishup

0 Kudos
Reply

781 Views
Lundin
Senior Contributor IV
(void)SCI1S1; (void)SCI1D; void == do nothing. The above code are so called null statements. To actually clear the flags, do like this: volatile uint8_t dummy; dummy = SCI1S1; dummy = SCI1D
0 Kudos
Reply

781 Views
bigmac
Specialist III

Hello Lundin,

 

When I have previously used expressions like

SCI1S1;

CW does appear to generate the required code, at least with the default compiler options, possibly LDA SCI1S1.  The void cast eliminates a compiler warning because the value is not assigned to a variable.

 

If it works, why make the code more complex by creating a dummy local variable?  Why your variable need to be volatile escapes me - is this also to avoid a compiler warning message?

 

Regards,

Mac

 

0 Kudos
Reply

781 Views
Lundin
Senior Contributor IV
The volatile dummy variable is there to ensure that the register is actually read no matter which optimizer settings that are active, or which C compiler that is used. If you just write SCIS1; you are the mercy of implementation-specific behavior and the code isn't portable between Codewarrior projects or to other compilers.
0 Kudos
Reply