Not receiving data through SCI

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

Not receiving data through SCI

2,468 Views
Tineras
Contributor I
#include <hcs12dp256.h>#define RDRF 0x20   // Receive Data Register Full Bit#define TDRE 0x80   // Transmit Data Register Empty Bitvoid init_SCI1(void){  SCI1BDH = 0;  SCI1BDL = 156; // baud rate to 9600  SCI1CR1 = 0x20; // 8-N-1  SCI1CR2 = 0x0C;}void init_PB(void) // Setup LEDs for data verification{   DDRB=0xFF;    // Output - Port B (Specifies Direction)  PORTB=0x01;   // Enable Port B0  DDRH|=0x00;   // Input - Port H - Direction of Switches  DDRJ|=0x02;   // Output - PJ1 - Sets an output on Pin 2  PTJ&=0xFD;    // LED Enable - Forces 0 to Pin 2}main(void){  init_PB();  PTJ &= 0xFE;  init_SCI1();      while(1)      {   while((RDRF & SCI1SR1)== 0){}; // RDRF never goes high ???        PORTB = SCI1SR1;  // Trying to display the output on LEDs      }}

I'm using a mc9s12dp256 on a Dragon 12 board.  This is my code for the receiver.  It's just quick and dirty just to receive some data.  This is my first attempt at SCI communication.  I have verified that the transmitter is sending 10 bits of data (start,data,stop).  It is running through the rs485 in single-line mode.  The RDRF bit never shows that the SCI1DRL register is full.  Any insight would be super helpful.
 
Thanks,
Aaron W.
Labels (1)
0 Kudos
5 Replies

535 Views
bigmac
Specialist III
Hello Aaron,
 
It is not clear from your code snippet, the manner in which you control the RS485 interface device.  I am not familiar with your Dragon 12 board.  However, for the MCU to receive data, the transmit section of the interface must be disabled, and the receive section enabled, otherwise the SCI won't see any incoming data.
 
It may be useful to check for the presence of data, using an oscilloscope, on each line of the RS485 pair, and at the RXD pin of the MCU.
 
Regards,
Mac
 
0 Kudos

535 Views
Tineras
Contributor I
I have confirmed the following through RS232 via serial cable:
 
-Transmitter-
Checked output on oscope
Received char from transmitter in hyperterminal
 
-Receiver-
Sent char to receiver from hyperterminal
 
I have also tried to connect the TxD and RxD directly on the chips with no luck.  Both boards are have a common ground.
 
I'm working on making a male to male serial cable right now to check rs232 connection from board to board.
 
Thanks
0 Kudos

535 Views
bigmac
Specialist III
Hello,
 
I am somewhat confused!
 
Initially you referred to RS485 interface, but now you refer to RS232.  Different drivers, and different voltage levels apply in each case.  Are you using a RS232-to-RS485 adaptor with the PC on which you run hyperterminal?  What device type is used for the RS485 interface on the Dragon 12 board?
 
Since RS485 (on a single pair) is half duplex, your SCI code will need to control the direction in which the RS485 interface operates.  This is not a requirement for RS232 operation.
 
Regards,
Mac
 
0 Kudos

535 Views
Tineras
Contributor I
I was just switching to the RS232 to verify that communication was at least happening.  Anyway, I figured it out.  I had not set the DDRJ register correctly.  Once I changed J0 to outputs, it worked perfectly.
0 Kudos

535 Views
Tineras
Contributor I
I managed to get data to the receiver directly by switching the communications jumper to urxd1 on both boards.  I'm still not sure why it won't work through the rs485, but I'm working on it.
0 Kudos