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.

TMS470 SCI Receiver problem



Hi guys

I'm using SCI to transmit data if the received command is correct. I can transmit data to hyper Terminal but not receive data. There is no new data in the receive buffer and the bus is unused.

My code is like this

void init_SCI(void){
  GCR = 0x08;                                                         // SYSCLK = 4*Oscil = 24MHz
  PCR = 0x01;                                                           // ICLK = SYSCLK
  SCI3PC1 = 0x03;                                                  // CLK output on Pin SCICLK
  SCI3CTL3 &= ~SW_NRESET;                                // Entering reset state
  CLKCNTL = 0x60;
  SCI3CCR |= TIMING_MODE_ASYNC;                    // Asynchronous timing
  SCI3CCR |= CHAR_8;                                           // 8 Data bits
  SCI3CCR &= ~COMM_MODE_ADDRESS;            // idle-line mode
  SCI3CTL1 |= RXENA;                                           // Allows the receiver to transfer data from shift buffer to the receive buffer
  SCI3CTL2 |= TXENA;                                            // Enable SCI to transfer data from SCITXBUF to SCITXSHF
  SCI3CTL3 |= CLOCK;                                            // Internal SCICLK
  SCI3CTL3 |= RX_ACTION_ENA;                           // Receive DMA/interrupt enabled
  SCI3CTL3 |= TX_ACTION_ENA;                            // Transmit DMA/interrupt enabled
  SCI3CTL3 |= RXERR_INT_ENA;
  SCI3HBAUD = 0x00;
  SCI3MBAUD = 0x01;
  SCI3LBAUD = 0x38;                                           

  SCI3PC2 |= RX_FUNC;                                       // SCIRX is the SCI receive pin
  SCI3PC3 |= TX_FUNC;                                         // SCITX is the SCI transmit pin

  SCI3CTL3 |= SW_NRESET;                                // Leaving reset state
}

void Read_from_SCI(int Command, int data[], int data1[]){
     int RXBUF;
     SCI3CTL1 |= RXENA;

     if ((SCI3CTL1 & 0x04) == 0x04){                        // new data ready to be read                                  *This line can not be fulfilled*
     RXBUF = SCI3RXBUF;                                        // read receive buffer
     SCIcommand(RXBUF, data, data1, Command); 
     }
     SCI3CTL1 &= ~RXENA;
    }

Is there anything wrong with my code??

Thanks a lot

Rui

  • Rui,

    I think you should comment those two lines in Read_from_SCI() function. :

    //SCI3CTL1 |= RXENA;

    //SCI3CTL1 &= ~RXENA;

    Here is an example:

    void SCI_Init(unsigned int baudValue)

    {
    /* USER CODE BEGIN (2) */
    SCIGCR0 = 1; // Module Out OF Reset
    SCIGCR1 = 0; //SWnRST = 0, Clears all Flag and can config
    SCIPI00 = 0x6; // TX/RX Pin Functional
    SCIGCR1 = 0x03000022; // Async, no parity, one stop bit
    SCICHAR = 7; // 8 data bits,
    SCIBAUD = baudValue; // Configure baud rate
    SCIGCR1 |= 0x80;
    // SWnRST = 1, SCI Config is done and should not be disturbed
    /* USER CODE END (2) */

    }

    unsigned char GetChar()
    {
       if (SCIRXREADY)
         return (SCIRD);
       else
         return 0;
    }

    Regards,

    Haixiao

     

     

  • Hi Haixiao

    Thanks for your quick reply. However it still doesnt work after changing. Do you have a idea what else might be the problem??

    Thanks

    Rui

  • Rui,

    It could be hardware or software problem. Could you please check if you have signals on SCI_RX pin when you type something in the Hyperterminal using a Oscillliscope?

    From software point of view, Can you try the code I included in the previous post? It works well on my bench with 470M devices.

    Regards,

    Haixiao

     

  • Here is the definations in my project.

    // Symbol Definitions
    #define SCIADDR 0xFFF7E500
    #define SCIGCR0 (*(volatile unsigned int *) (SCIADDR))
    #define SCIGCR1 (*(volatile unsigned int *) (SCIADDR+0x4))
    #define SCIFLR  (*(volatile unsigned int *) (SCIADDR+0x1C))
    #define SCICHAR (*(volatile unsigned int *) (SCIADDR+0x28))
    #define SCIBAUD (*(volatile unsigned int *) (SCIADDR+0x2C))
    #define SCIRD   (*(volatile unsigned char *)(SCIADDR+0x37))
    #define SCITD   (*(volatile unsigned char *)(SCIADDR+0x3B))
    #define SCIPI00 (*(volatile unsigned int *) (SCIADDR+0x3C))
    #define SCIPI07 (*(volatile unsigned int *) (SCIADDR+0x58))
    #define SCITXREADY (SCIFLR & (0x0800))
    //#define SCITXEMPTY (SCIFLR & (0x0800))
    #define SCIRXREADY (SCIFLR & (0x0200))

    With all these settings and it works well with the TMS470M USB stick. It looks that you are use a R1x device.

    Please be aware that the TMS470R1x series is not recommended for new designs.  Please see the full 'NRDN' notice here.

    Soon TI will be launching the new TMS470M series of microcontrollers.  This series will feature greater ARM CPU performance and a similar peripherial set to the TMS470R1 Series of microcontrollers.  Please come back soon for more information about the TMS470M Series of microcontrollers.  The product preview for the first two microcontrollers in the TMS470M series is available here: TMS470MF0660x - SPNS157. The TMS470M Series Technical Reference Manual is available here: TMS470M TRM.

     

    I don't have a board with SCI connection to the PC with R1x device. So I can not provide a demo code with R1x devices.

    Regards,

    Haixiao

  • Hi Haixiao

    I can see the signal from Oscillliscope. I will try to use your code. Thanks a lot

    Regards

    Rui

  • Hi  Haixiao

    It seems that my ReceiveReady bit will never be set. I have already enable the receive interrupt. Do you know what might be the problem?

    Thanks a lot

    Rui

  • Rui,

    Here is some SCI source code running well in R1x devices.

    I don't know which device you are using. So, I assume the base address of you sci is 0xfff7f400. Please modify that in the *.cmd file if necessary.

    I don't have a UART connection to the PC. Therefore I connect the SCIRX and SCITX pins to do an external loopback.

    I just pick up one baudrate. You need to modify according to your PLL and crystal setup.

    This code runs well in my R1x setup. Helpful, it can help you find out what is wrong with your code.

    Good luck.

    Source Code: 0535.SCI_EXam.zip

    Regards,

    Haixiao

  • Normal 0 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4

    Normal 0 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4

    Hi Rui,

    I don’t know which device you’re using, and I’m also new to TMS470R1x series microprocessor.

    I'm not sure if it's any help, but the following is my thought if you’re using the TMS470R1x device:

     

     Did you define the interrupt handler routine that will handle the SCI generated RX interrupt (since you have enabled the receive DMA/interrupt in your code)?

    1.  If not, I think what happens here is that when RX interrupt occurs , the code is then unable to return from the interrupt handling routine.

     For IAR Systems software, keyword:  __irq __arm (the keyword may be different for different C-compiler for ARM)

    Example, setup for SCI 1:

    void init_SCI(void){

    .

    .

    .

          // Interrupt sources

           REQMASK = (1 << CIM_SCI1RX); //enable SCI 1 RX interrupt

     

    }

    --------------------------------------------

    __irq __arm void irq_handler()

    {

       switch ((0xff & IRQIVEC) - 1)  

      {  

        case CIM_SCI1RX :  

            UART1RX_function(); // Call UART RX ISR function.

          break;  

      } 

    }

     

    void UART1RX_function(void)

    {        SCI1TXBUF = SCI1RXBUF;    // Echo back any Rx'd byte on SCI 1

    }

     

    2. If you have already defined your RX interrupt handler, then you may clear the RXRDY bit (SCI receiver ready flag) by doing a read from SCIRXBUF or SW nRESET in your ISR (spnu196 TMS470R1x SCI reference guide, page 36).

    Thus, your RXRDY bit (SCI3CTL1_bit.RXRDY) is cleared upon return from interrupt.

     

    3. Else, disable the RX interrupt in your code and use the polling method (if possible) by disabling the following line. Just to see your SCI hardware is working or not:

    //SCI3CTL3 |= RX_ACTION_ENA;                           // Receive DMA/interrupt enabled

    And, do something as below:

    Polling: if ((SCI3CTL1 & 0x04) == 0x04)

                                    UART3RX_function();

                    else

                                     goto Polling;

     

     

    Best Regards,

    Soo

  • Thanks a lot for your code, Haixiao and Soo

    I have tried my code on an EVB, everything is fine. Therefore i assume that the SCI3 port of my board is broken. I will switch to another port to see what will happen. Thanks again for your kind help :)

    Regards

    Rui

  • Haixiao

    I am looking for the example code referenced in this message. 0535.SCI_EXam.zip

    The link is broken, could you add the code again?

    Prasad