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.

Problem when sending multiple characters to F28335 through SCI

Other Parts Discussed in Thread: CONTROLSUITE

Hi,

I have a problem when sending serial from hercules emulator to F28335 using SCI communication.

I use code from C2000 teaching rom from TI which is Lab9_4.c. The code should wait for character 'Texas' to be received and reply with 'Insturments!' to terminal. The program works find, i.e responds,  when I send character one by one by typing 'T' in hercules then send, type 'e' then send and so on. But if I type 'Texas' in hercules and then click send, the program don't send the response.

I check the content of variable buffer when the program generate receive interrupt. when I type character 'Texas' on hercules and click send the contents are:

buffer[0] = 'T', buffer[1] = '.', buffer[2] = '.', buffer[3] = 'X', buffer[4] = '.'

I use:

Board: Technosoft MSK28335

CCS version 4.1.2

terminal emulator: Hercules

the code I use:

6064.Lab9_4.c
//
//      Lab9_4: TMS320F28335
//      (c) Frank Bormann
//
//###########################################################################
//
// FILE:	Lab9_4.c
// 
// TITLE:	DSP28 SCI - Communication to PC - Terminal
//			SCI-Setup: 9600 Baud, 8 Bit , ODD Parity , 1 Stopbit	
//			SCI - TX and RX - Interrupt are used in this Lab 
//			SCI - TX and RX - FIFO are used in this Lab
//			DSP waits for "Texas" and answers with "Instruments"
//			Watchdog active , serviced solely in main-loop 
//###########################################################################
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  3.0 | 08 Jul 2009 | F.B. | adapted for ControlCard28335 @ 20MHz
//  3.1 | 15 Nov 2009 | F.B  | Lab9_4 for F28335 @30MHz and PE revision 5
//###########################################################################
#include "DSP2833x_Device.h"
#include <string.h>
  
// External Function prototypes
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);

// Prototype statements for functions found within this file.
void Gpio_select(void);
void SCIA_init(void);
interrupt void SCIA_TX_isr(void);	 // SCI-A Transmit Interrupt Service
interrupt void SCIA_RX_isr(void);	 // SCI-A Receive  Interrupt Service

// Global Variables
char message[]={" Instruments! \n\r"};

//###########################################################################
//						main code									
//###########################################################################
void main(void)
{
	InitSysCtrl();	// Basic Core Initialization
					// SYSCLK=150MHz, HISPCLK=75MHz, LSPCLK=37.5MHz
	EALLOW;
   	SysCtrlRegs.WDCR= 0x00AF;		  // Re-enable the watchdog 
   	EDIS;			// 0x00E8  to disable the Watchdog , Prescaler = 1
   					// 0x00AF  to NOT disable the Watchdog, Prescaler = 64
	
	Gpio_select();	// GPIO9, GPIO11, GPIO34 and GPIO49 as output
					// to 4 LEDs at Peripheral Explorer			
	
	InitPieCtrl();		// default status of PIE; in DSP2833x_PieCtrl.c
	
	InitPieVectTable(); // init PIE vector table; in DSP2833x_PieVect.c
	
	// re-map PIE - entry for SCI-A-TX and SCI-A-RX
	EALLOW;  
   	PieVectTable.SCITXINTA = &SCIA_TX_isr;
	PieVectTable.SCIRXINTA = &SCIA_RX_isr;
   	EDIS;    
   		
   	SCIA_init();  // Initalize SCI 
   
    // Enable SCI-A TX Interrupt Group9 interupt 2
	PieCtrlRegs.PIEIER9.bit.INTx2 = 1;
	// Enable SCI-A RX Interrupt Group9 interupt 1
	PieCtrlRegs.PIEIER9.bit.INTx1 = 1;


	// Enable INT9 for SCIA-TX and SCIA-RX:
    IER = 0x100;
    
	// Enable global Interrupts and higher priority real-time debug events:
   	EINT;   // Enable Global interrupt INTM
   	ERTM;   // Enable Global realtime interrupt DBGM
   	
	while(1)
	{    
	  	EALLOW;
		SysCtrlRegs.WDKEY = 0x55;			// Service watchdog #1
		SysCtrlRegs.WDKEY = 0xAA;			// Service watchdog #2
		EDIS;
	}
} 	

void Gpio_select(void)
{
	EALLOW;
	GpioCtrlRegs.GPAMUX1.all = 0;			// GPIO15 ... GPIO0 = General Puropse I/O
	GpioCtrlRegs.GPAMUX2.all = 0;			// GPIO31 ... GPIO16 = General Purpose I/O
	
	GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1;	// SCIRXDA
	GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1;	// SCITXDA	
	
	GpioCtrlRegs.GPBMUX1.all = 0;			// GPIO47 ... GPIO32 = General Purpose I/O
	GpioCtrlRegs.GPBMUX2.all = 0;			// GPIO63 ... GPIO48 = General Purpose I/O
	GpioCtrlRegs.GPCMUX1.all = 0;			// GPIO79 ... GPIO64 = General Purpose I/O
	GpioCtrlRegs.GPCMUX2.all = 0;			// GPIO87 ... GPIO80 = General Purpose I/O
	 
	GpioCtrlRegs.GPADIR.all = 0;
	GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;		// peripheral explorer: LED LD1 at GPIO9
	GpioCtrlRegs.GPADIR.bit.GPIO11 = 1;		// peripheral explorer: LED LD2 at GPIO11

	GpioCtrlRegs.GPBDIR.all = 0;			// GPIO63-32 as inputs
	GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;	// peripheral explorer: LED LD3 at GPIO34
	GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

	GpioCtrlRegs.GPCDIR.all = 0;			// GPIO87-64 as inputs
	EDIS;
} 

void SCIA_init()
{    
   	SciaRegs.SCICCR.all =0x0027;   	// 1 stop bit,  No loopback 
                                   	// ODD parity,8 char bits,
                                   	// async mode, idle-line protocol
	SciaRegs.SCICTL1.all =0x0003;  	// enable TX, RX, internal SCICLK, 
                                   	// Disable RX ERR, SLEEP, TXWAKE
	
	// SYSCLOCKOUT = 150MHz; LSPCLK = 1/4 = 37.5 MHz
	// BRR = (LSPCLK / (9600 x 8)) -1
	// BRR = 487  gives 9605 Baud
	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

	SciaRegs.SCIFFTX.all = 0xC060;	// bit 15 = 1 : relinquish from Reset
									// bit 14 = 1 : Enable FIFO
									// bit 6 = 1 :  CLR TXFFINT-Flag
									// bit 5 = 1 :  enable TX FIFO match
									// bit 4-0 :  TX-ISR, if TX FIFO is 0(empty) 
	SciaRegs.SCIFFCT.all = 0x0000;	// Set FIFO transfer delay to 0
	
	SciaRegs.SCIFFRX.all = 0xE065;	// Rx interrupt level = 5

	SciaRegs.SCICTL1.all = 0x0023;	// Relinquish SCI from Reset 
}  

// SCI-A Transmit Interrupt Service
interrupt void SCIA_TX_isr(void)	 
{
	unsigned int i;
	// copy 16 character into SCI-A TX buffer
	for(i=0;i<16;i++) SciaRegs.SCITXBUF= message[i];
	// Acknowledge this interrupt to receive more interrupts from group 9
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;  
}

// SCI-A Receive Interrupt Service
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;  
}

//===========================================================================
// End of SourceCode.
//===========================================================================

It would be helpful if someone could give any suggestion or information to this problem

Thanks

  • Hi,

    Did you try reducing your buffer size from buffer[16] to buffer[4] ie 0 to 4

    for (i=0;i<4;i++)
    
    buffer[i]= SciaRegs.SCIRXBUF.bit.RXDT;

    Regards,

    Gautam

  • Hi Gautam,


    Thanks for your reply. I've tried your suggestion by changing the size of buffer to 5 in SCI receive ISR function:

        char buffer[5];
      for (i=0;i<5;i++) buffer[i]= SciaRegs.SCIRXBUF.bit.RXDT;

    but still not working. The content of buffer still not the character 'T' 'e' 'x' 'a' and 's' and so the TMS does not send the response to hercules

    Regards,

    Novan

  • Novan, I forgot to ask you What buffer value do you receive? Garbage value??

  • Gautam,

    In receive interrupt routine I place a break point, so when I send 5 characters, the program will go into the ISR and stop there. after that I step over the program and check the content of variable buffer

    When I type 'Texas' in hercules and send it to the board, I get these characters:

    buffer[0] = 'T'

    buffer[1] = 'Y'

    buffer[2], buffer[3], buffer[4]  = '.'

    It looks like only the first character that's been received correctly, I don't know why..

    Regards

  • Instead of using an interrupt, try with this structure:

    while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for RRDY/RXFFST =1 for 1 data available in FIFO
    
    // Check received character
    ReceivedChar[i] = SciaRegs.SCIRXBUF.all;
    i++;

    Regards,

    Gautam

  • I've disabled the watchdog and receive interrupt and use below code in main

    int main(){
       ...
       char ReceivedChar[5];
       int i = 0;
       ...
       while(1)
       {
          ...
          while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } 
          // Check received character
    		
          ReceivedChar[i] = SciaRegs.SCIRXBUF.all;
          i++;
    		
          if (i == 5){
             SciaRegs.SCIFFRX.bit.RXFIFORESET = 0;	// reset RX-FIFO pointer  
    	 SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;	// enable RX-operation
    	 i = 0;
    			
          }
       }
    }

    the result still the same with result when using interrupt. The content of the variable ReceivedChar still not the word I send from hercules.  I send the word 'Texas' but the content of ReceivedChar are:

    ReceivedChar[0] = T

    ReceivedChar[1] = Y

    ReceivedChar[2], ReceivedChar[3], ReceivedChar[4] = '.'

    Regards

  • What if you give a carriage return after every letter? T(enter)E(enter)X(enter)A(enter)S(enter)

  • Gautam,

    I've tried your suggestion, but still not working. The content of receive buffer still not the word I send..

    I wonder if F28335 can not receive multiple character that send at once through SCI.

    FYI, I've tried the code with three different boards, and still the same.

    I wonder if TI guy could give some information to this issue..

    Regards

  • Hello Novan,

    If you try example from C:\ti\controlSUITE\device_support\f2833x\v133\DSP2823x_examples_ccsv4\sci_echoback, does it work?

    Best regards,

    Maria

  • Hi Maria,

    Thanks for the response. I've tried the code, and it works. It echoes back the character I type in hercules.

    It seems that there is no problem if I send only a single a character at a time. The problem is when I type multiple character in hercules and send it through SCI, the F28335 could not handle it.

    Regards,

    Novan

  • Novan, try introducing some delay in your routine. This might help you in getting data correctly in your buffer.

    Regards,

    Gautam

  • I finally could send 5 characters simultaneously through SCI with both code that use FIFO receive interrupt and without interrupt by polling RXFFST bits

    for code that use polling, I have to make small changes in testing RXFFST bits, so that the FIFO buffer wait for 5 characters to come and then process it

    in Example_2833xSci_Echoback.c the testing part is

    while(SciaRegs.SCIFFRX.bit.RXFFST != 1) { }

    and I change it to

    while(SciaRegs.SCIFFRX.bit.RXFFST < 5) { }

    to make FIFO buffer to wait until 5 characters been received and the process it

    For program that use receive FIFO interrupt, Lab9_4.c, I make a very fundamental mistake, or you can call it a stupid one.. The setting of SCI format data used in the code is using ODD parity. But the hercules is set to use no parity..

    Thanks for your help. Gautam and Maria

    Regards,

    Novan

  • That's Great, Novan!

    Goodluck & Regards,

    Gautam

  • Hi, guys,

    I set the hercules as 'ODD' parity already but the 28355 dsp still didn't give any response after typing ' Texas'.

    somebody faced the same problem?

    regards,

    alex