Troublewith SCI transmit on S12C32

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

Troublewith SCI transmit on S12C32

2,326 Views
pdarg
Contributor I
Hi,

I am trying to write a simple program to output data on the sci port of a MC9S12C32. My problem is that when I write a value to the SCIDRL register, the value is not written and 0x00 is written instead. However when I write to SCIDRH it works fine.

Below is the code i am trying to run.

Code:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12c32.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12c32"

#define BAUD_RATE_DIVIDER 130 // 9600  Baud


void sendData(void);
void initialize(void);
void interrupt 20 sciHandler(void);

int sendCount;
int done;

void main(void) {

  initialize();
  EnableInterrupts;
 
  sendData();

  for(;;)
    if(done) { break; }}void initialize(void) { // initalize the system  done = 0;  sendCount = 0;    // clear flags  SCISR1;  SCIDRL = 1;    // initialize SCI module    SCIBDH = 0x00;  SCIBDL = BAUD_RATE_DIVIDER;                                      SCICR1 = 0x00;  SCICR2 = 0xC8;// turn on tx and related interrupts}void sendData(void) {  SCIDRH = 0xFF; // this works and writes 0x40 to the register (T8)  SCIDRL = 0x55; // this writes 0x00 to the register    // I've also tried this and got the same results  //asm {  //  movb  $FF,SCIDRL;  //}     if(sendCount++ == 100) { done = 1; }}void interrupt 20 sciHandler(void) {  if(SCISR1_TC){// Transmit Complete    //sendData();  }  if(SCISR1_TDRE){// Transmit Data Register Empty     if(done == 0){      sendData();    }  }}

 

Any thoughts on what I am doing wrong?


Labels (1)
0 Kudos
5 Replies

478 Views
JimDon
Senior Contributor III
When you write to the register it is Tx data, when you read from this register it is Rx data, so unless you you just happen to have received the exact same data you  sent, I would expect the Rx data to be 0 most of the time.

0 Kudos

478 Views
pdarg
Contributor I
Thanks for the quick replies, I appreciate it.

I am a little confused. I am viewing the registers' content using the True Time simulator with Codewarrior. When you mention reading the value of of SCIDRL I am assuming you mean that the simulator's memory watch feature reads the register and the read only returns the value contained in the Rx register, not Tx.

I am still not able to view the contents even when LOOP and RE are set. Perhaps I am missing some concept here.

I was writing to the SCIDRH register as a proof of concept that I was actually performing the operation correctly, not for any functional reason.

Another thing that has me puzzled is that only one byte is sent. Since the interrupts are enabled I would expect that the TDRE interrupt would be called once for each byte I write into SCIDRL.

I am a beginner with the HCS12 and feel like I just dont fully understand some of the concepts involved here.
0 Kudos

478 Views
JimDon
Senior Contributor III
Well, the concept you may be missing is that the Tx data register simply CAN'T be read at all, not in the simulator or on the real thing, because it shares an i/o port address with the Rx registers. Although there really are two registers on the chip, a write to that port address writes to the Tx register, while a a read reads the Rx register, a completely different register. This applies to the Low part of the register, bu the high part is slightly different with regards to bit T8. If you look in the spec, that is the same bit for both read and write. Odd, but thats the way it is. You can stop worrying about that. What you see is what would be expected.

If you are using CodeWarrior, try generating sample code in Processor Expert. As far as I know this should work in the simulator at least the Tx interrupts should happen.
There are some samples here that might help as well. These were wirtten for the DP, and may apply to the C version as well.








Message Edited by JimDon on 2008-02-09 01:00 AM
0 Kudos

478 Views
pdarg
Contributor I
Thanks, I was able to figure it out.
0 Kudos

478 Views
allawtterb
Contributor IV
For starters, you can't write data to SCIDRL and then read that data back.  When you read SCIDRL it is reading received data.  If you want a write to SCIDRL and then read it from SCIDRL you will need to set the LOOPS bit in SCICR1. There should be no reason to read/write to SCIDRH unless you are doing 9-bit data transfers which you are not (you enable this by setting the M bit in SCIDRL, but I don't think you are wanting a 9-bit data transfer).
 
edit: For information on the SCI module for the S12 take a look at:


Message Edited by allawtterb on 2008-02-08 10:56 PM
0 Kudos