This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UART - Choosing lsb or msb first

Hi,

I am using the Peripheral Explorer kit with f28335. 

I am trying to communicate with a device using SCI ports. I have problems sending and receiving messages because of the messages are being sent with msb first and not lsb first, while the other device is doing the opposite.

I am using the example in Lab9 that was included with the peripheral explorer, using DSP2833x_Sci.c

Is there any way that I can change the direction of the bits that are being sent / received?

  • Hi Jack,

    Refer this post from Sal : e2e.ti.com/.../1582796
    Let me know if this helps you answer your question.

    Regards,
    Gautam
  • Jack,

    The SCI on the F28335 always transmits LSB first, MSB last (see SPRUFZ5A, p.15, Figure 1-3).  If you need it sent MSB first, you would have to reverse the bit order prior to writing the word to the TXBUF.  There is actually instruction support in the C28x CPU at the assembly code level - the FLIP instruction.  You could write a fairly efficient little function that you pass the TX word to.  It flips the bits, and then writes it to the SCI TXBUF.

    Regards,

    David

  • Ok, I managed to flip the bits correctly before adding the data into the TX buffer. Works very good. But I still have problems when receiving data. When I try to read the received data (10 bytes long, added in a 10 bytes array), I can only read one byte. And this byte is wrong ( I have to flip the bits in this byte to get the correct byte).

    Maybe since the Msb is received first, and then the lsb, the start bit and the stop bit is flipped aswell? Which means that the data sent looks like : stop bit / data bits / start bit. Is that possible?
  • Jack,

    I've always thought standard UART protocol is to transmit LSB first.  I've never seen a UART that transmits MSB first.  So, I wonder why you have a device doing MSB first.  Regardless, a UART port cannot reverse the order of the start and stop bits.  You always have to have start, data, stop.  If you have some weird UART that transmits MSB first, it will still be start, MSB, ..., LSB, stop.  It has to be that way.  Otherwise, the UART communication will fail.

    When you say you can only read one byte, are you using the SCI FIFOs?

    - David

  • I have pasted my code below. I am new to serial communication in c, so I am not sure if I am handling everything correctly (I should maybe check and clear some error and overflow flags etc..).

    When I send data to the Peripheral Explorer, i.e. 10 bytes long,, the buffer array gets updated with a same byte for all indexes.

    void SCIA_init()
    {    
       SciaRegs.SCICCR.all =0x0007;   	// 1 stop bit,  No loopback 27
                                       	// ODD parity,8 char bits,
                                       	// async mode, idle-line protocol
       SciaRegs.SCICTL1.all =0x0003;  	// enable TX, RX, internal SCICLK, 
                                      	// Disable RX ERR, SLEEP, TXWAKE
    	
       SciaRegs.SCIHBAUD    = 487 >> 8;	// Highbyte
       SciaRegs.SCILBAUD    = 487 & 0x00FF;	// Lowbyte
    
       SciaRegs.SCICTL2.bit.TXINTENA = 1; 	// enable SCI-A Tx-ISR
       SciaRegs.SCICTL2.bit.RXBKINTENA = 1; // enable SCI_A Rx-ISR
    
    
       ScibRegs.SCIFFTX.all = 0xC028;
       ScibRegs.SCIFFRX.all = 0x0028;
     
       SciaRegs.SCIFFCT.all = 0x0000;	// Set FIFO transfer delay to 0
    	
       SciaRegs.SCIFFRX.all = 0xE065;	// Rx interrupt level = 8
    
       SciaRegs.SCICTL1.all = 0x0023;	// Relinquish SCI from Reset 
    } 
    
    
    interrupt void SCIA_RX_isr(void)
    {
    	int i;
    	char buffer[16];
    	for (i=0;i<16;i++) buffer[i]= SciaRegs.SCIRXBUF.bit.RXDT;;
    
    	//if (strncmp(buffer, "Texas", 5) == 0)
    	//{
    	//	SciaRegs.SCIFFTX.bit.TXFIFOXRESET =1;  // enable TXFIFO
    	//	SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1 ;  // force TX-ISR
    	//}
    	 	
    	SciaRegs.SCIFFRX.bit.RXFIFORESET = 0;	// reset RX-FIFO pointer
    	SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;	// enable RX-operation
    	SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;    // clear RX-FIFO INT Flag
    	PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;
    }
    

  • I just checked the signal outputs from the device and the Peripheral Explorer. The device I am communicating with, has a normal High signal when it is idle, while the Peripheral Explorer has a low signal. I read that "The SCI uses a NRZ (Non-Return-to-Zero) format, which means that in an inactive state the SCIRX and SCITX lines will be held high.".

    Why is the SCI output on my Peripheral Explorer held low? Is there a register that i must change?