9s12dp256 serial com

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

9s12dp256 serial com

2,274 Views
yklein
Contributor I
Hi,
I wrote a code with ICC12 to receive serial com on SCI1 and display it
on the screen (prinf) using interrupt. all I'm getting is a range of
values between 252 and 255. why?
here is my code:

#include
#include

void initialize(void);
void sci_isr (void);
unsigned int rxData;
unsigned int i; /* the message received. */

#pragma interrupt_handler sci_isr

//Serial Com 1 Interrupt
void sci_isr (void){
if (SCI1SR1&0x20){ rxData = SCI1DRL; /* The receiver is full. Read a byte. */
printf(" %d \r", rxData);}
}
}

void initialize(){
i=0;
SCI1BDL=156;SCI1BDH=0x00; //Set Boud rate to 38,400
SCI1CR1=0x00;
SCI1CR2=0x24; //enable SCI reciever interrupt
*(void (**)())0x3fd4=sci_isr; //Serial Com. #1 interrupt
asm("cli");
}

void main (void){
initialize();
while(1){}
}
Labels (1)
0 Kudos
5 Replies

526 Views
bigmac
Specialist III
Hello,
 
A further observation - it is not a good idea to call the print() function from within the ISR because it is a complex function, and its execution time may be unpredictable.  If it took longer than about 260 microseconds to execute, this could create a problem for your code.  Try reducing the baud rate from 38400, and see if the problem persists. 
 
The more usual approach is to store the incoming bytes in a global buffer that can be read and displayed from within main(). 
 
What serial port does the printf() function use - is there a conflict with your use of SCI1?
 
Regards,
Mac
 
0 Kudos

526 Views
yklein
Contributor I
thanks for the help. I found my problem I miss calculate the baud rate register value.
it's working now.
0 Kudos

526 Views
rocco
Senior Contributor II
I can't offer much help, except to say that if the values between 252 and 255 exclude 253 (in other words, 252, 254 and 255 only), then it's could be indicative of too high a baud rate at the receiver.
0 Kudos

526 Views
bigmac
Specialist III
Hello,
 
You might add code to check whether you are getting framing errors.  This would also indicate a mismatch between the receive and the incoming baud rate.
 
Regards,
Mac
 
0 Kudos

526 Views
mke_et
Contributor IV
Well, first make sure everything is 'set up' right.

Transmit a known string out the serial tx port. In poll mode. If that works, then you know you probably have things 'set up' right, like baud rate and such.

Then do a simple loop of poll the input and if it finds anything send it to the output. That will tell you if you have your rx configured right.

THEN start working on a serial interrupt to buffer routine.

Divide and conquer.
0 Kudos