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.

CC2540 UART Rx Problem

Other Parts Discussed in Thread: CC2540, BLE-STACK

HI All,

I am developing with cc2540 some applications. We are using cc2540 with two purposes with BLE stack and without BLE stack. Since we do not want to change mcu so we want to use CC2540 as 8051 mcu chip. I am developing application without BLE stack, and I have written UART drivers, The drivers for TX works fine for RX no work.

When I sent data from PC to device the data is appearing on the Rx pin which i verified through oscilloscope, but it never trigger Rx ISR interrupt. And I also debug through Registers, In IAR EW register debug view I checked that all registers (UART1) and (Interrupt Register) are configured accordingly. I do not understand why Rx interrupt is not triggered. So please help me find the bug. Thanks in advanced

  • Hello SATTAR MALOKANI,
    ISR-based serial communication is not recommended, because of the radio-interrupts that can both preempt and block your UART Isrs. I recommend that you use DMA. Look at the drivers that comes with the BLE stack install:

    ti.com/ble-stack (Look for hal_uart.c or open a project that use this driver)

    If you only need one channel you can use DMA channel 3&4:
    e2e.ti.com/.../1106877

  • Hi Eirik V,

    Thanks you very much for your immediate reply, as i mentioned in my earlier post that I am not using BLE stack and these drivers are written standalone not to be used with BLE stack. IN cc2540 we just want to use MCU 8051 and other prepherals like USART, ADC and SPI.

    I understand that CC2540 is not built just for use as 8051 MCU, as in our company we are using CC2540 (already for BLE in other Applications) so we do not want to move other chip mcu or other processor. So for that reason i am writing application driver without using BLE stack. So I am writing drivers for SPI, UART and ADC, etc.

    So please help me figure out that why Rx ISR is not triggered. (Again I want to mention that this application will not use BLE so there is no issue with Radio Interrupts)

    Thanks

    Sattar Malokani
  • You can extract the drivers only from the BLE stack install without using BLE:
    C:\Texas Instruments\BLE-CC254x-1.4.1.43908\Components\hal\target\CC2540EB
    C:\Texas Instruments\BLE-CC254x-1.4.1.43908\Components\hal\include
    There you will for example find:
    hal_uart.h
    hal_uart.c
    _hal_uart_dma.c
    _hal_uart_isr.c
  • Hi Eirik V,

    Thank you for your suggestion, as per your suggestion I extracted Hal UART driver from the latest BLE stack. The extracted drivers also works for only Tx ISR and Tx communication. Rx ISR is never triggered Even though data signal appears on the Rx pin of cc2540.

    I have tested 5 chips with me in the Lab all are behaving same; Tx on all is working fine and Rx is not working. My PCB layout is UART1 and Port Alt1 (P0_5=Rx and P0_4=Tx). So I have concluded that chip has problem with Rx ISr at UART1 and Port Alt1. when I made jumper from UART1 to UART0 and Port Alt1 (same port P0) then both Tx and Rx works fine (I have not tested UART1 with P1 because making that jumper is difficult in my PCB). And every data I sent from my Pc to CC2540 board is received correctly and Rx ISR is triggered when it see data on Rx pin.

    I just make the change from UART1 to UART0 and Port AL1 (P0) is same and after that it started working. I spent couples of days and surprised to know that chip can have internal problems. I made UART1 and UART0 configurations exactly same (for examples baud rate dataflow etc.) just small change is UART1 is at P0_5=Rx P0_4=Tx, and i moved it to UART0 (Tx is at P0_3) and (Rx is at P0_2.). And it started worked, mean while surprised that P0_2 and P0_3 pins works fine for bot Rx and Tx.

    So from this experiment i concluded that UART1 for Port P0 Rx Isr is unresponsive, where as Tx is perfect working.

    If you want to test scenario, I have complete project for HAl UART extracted drivers and for my on UART drivers, I have created project using IAR EW 9.30.1 version and i can send to you.

    And some where in this forum i also reader that other person has also same problem for UART1 ALT1 Port (p0) for them Tx is working fine and Rx is never triggered wit ISR enabled.

    Thanks

    Sattar Malokani
  • Hi Sattar Malokani,

    I have exactly the same problem but using UART1 on P1 alt 1. Did you find already any solution on your problem? Exactly as yours UART0 works OK.

    Thank you in advance!
    BR
    Refik

  • Hi Rafik Halilo,

    yes I found solution for that one TI employee clear my confusion.

    By default USART0 is available on port P0, and default mode is SPI. and you can see that in datasheet I/O GPIO table SPI clock bit is conflicting with RX pin of USART1.

    So there exits two solutions.

    1. Give higher priority to USART1 over USART0.

    2. Shift USART0 to alternate location 2, when you shift then USART0 is available on P1. so P0 is now free to be used.

    I tried both methods and they working fine.

    I hope this will work with you.

    regards,

    Sattar Malokani

  • Please make sure in your case is USART0 is already setup some where in your code on P1, Then in this case shift USART0 to P0 or give higher priority to USART1 by priority I mean precedence to use pins. So please read these sections carefully 7.6, 7.6.4 and 7.6.5 also please refer to below post

    e2e.ti.com/.../484544
  • Hi Sattar,

    Thank you very much for your fast response and meaningful information. In my situation I am trying to use two different ports P0 for Uart0 and P1 for UART1(P1_6 - Tx, P1_7 - Rx). I've already checked that there may be a conflict with other peripheral (in my case MI and MO of UART0_SPI and Timer3 Cap/Compare pins). Regarding the UART0_SPI isn't it enough to choose UART by making one U0CSR:MODE bit? I've allready configured UART0 in this mode and it is working fine., but UART1 can only transmit data.
    Could you please provide me with some sample code of any working configuration of both UARTs?

    Thank you in advance!
    BR
    Refik
  • Hi Refiq,

    first make sure that your both configurations are correct, and you can view register inside IAR EW debugger,

    and configuration should be like that.

    // if USART port Alternative 1 is required and

    //USART0 is required on P0

    #define P2DIR_PRIP0_USART0 (0x00 << 6) // USART 0 has priority, then USART 1, then Timer 1
    #define P2DIR_PRIP0_USART1 (0x01 << 6) // USART 1 has priority, then USART 0, then Timer 1

    PERCFG &= ~0x01; /* Configure USART0 for Alternative 1 */ 

    P0SEL |= 0x0C; /* Configure Port P0 pins for UART Peripheral function */

    //USART1 is required on P0

    PERCFG &= ~0x02; /* Configure USART1 for alternative 1 */
    P2DIR = P2DIR_PRIP0_USART1; /* Give USART1 priority on P0*/
    P0SEL |= 0x30; /* Configure Port P0 pins for UART Peripheral function */

    * Else USART port Alternative 2 is required */

    // USART0 is required on P1

    PERCFG |= 0x01; /* Configure USART0 for Alternative 2 */
    P1SEL |= 0x30; /* Configure Port P1 pins for UART Peripheral function */

    /* USART1 is Desired  on P1*/

    PERCFG |= 0x02; /* Configure USART1 for alternative 1 */
    P1SEL |= 0xC0; /* Configure Port P1 pins for UART Peripheral function */

    Above code is only to select USART either on P0 or P1. once you configures this, then you have to select what you want on USART, You want UART Mode or SPI Mode,

    In your case you want UART mode so configuration should be like this:

    // USART1 baud rate 115200

    U1BAUD = 0xD8;

    U1UCR = 0x02;

    U1GCR = 0x0B;

    U1CSR = 0xC0;

    //USART0 baud rate 115200

    U0BAUD = 0xD8;

    U0UCR = 0x02;

    U0GCR = 0x0B;

    U0CSR = 0xC0;

    then next thing is interrupt configuration and should be like this, 

     /* USART0 is desired */

    URX0IF = 0;
    U0CSR |= 0x40; /* UART Receiver enable (this is already configured above but for make RE is enable so configure again)*/
    IEN0 |= 0x04;

    /* USART1 is desired */

    URX1IF = 0;
    U1CSR |= 0x40; /* UART Receiver enable */
    IEN0 |= 0x08;

    Now you have succesully configured UART on both ports, last touch is to enable global interrupt. 

    In IAR EW put this intrinsic function __enable_interrupt(); just before while(1);

    or you can do by this 

    IEN0 |= 0x80;

    I hope this will work. 

    regards, 

    Sattar Malokani

  • Hi Sattar,

    Thank you very much for your detailed explanation! I've spent whole day today checking different configurations, but without any result. Finally I've decided to blame the HW and it worked !!! :)
    First I was working with one very old TI USB dongle. Now I've tried with my own board and it worked. I don't know why the dongle is not working but I will investigate this later.
    Thank you again for all of your help!
    BR
    Refik