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 Keyfob

Other Parts Discussed in Thread: CC2540

Hi all

I am trying to send the word "hello" from CC2540 of keyfob UART0 alt.2 

P1.4 for rx

P1.5 for tx

Now , I placed the next code under function SimpleBLEPeripheral_Init in file simpleBLEPeripheral.c

(I don't sure this is the right place)

The code is:

// For keyfob board set GPIO pins into a power-optimized state
// Note that there is still some leakage current from the buzzer,
// accelerometer, LEDs, and buttons on the PCB.

P0SEL = 0; // Configure Port 0 as GPIO
P1SEL = 0; // Configure Port 1 as GPIO
P2SEL = 0; // Configure Port 2 as GPIO

P0DIR = 0xFC; // Port 0 pins P0.0 and P0.1 as input (buttons),
// all others (P0.2-P0.7) as output
P1DIR = 0xFF; // All port 1 pins (P1.0-P1.7) as output
P2DIR = 0x1F; // All port 1 pins (P2.0-P2.4) as output

P0 = 0x03; // All pins on port 0 to low except for P0.0 and P0.1 (buttons)
P1 = 0; // All pins on port 1 to low
P2 = 0; // All pins on port 2 to low

//noam
PERCFG |= 0x01; //usart0 alt.2
U0GCR = 8;
U0BAUD = 59;
U0CSR = 0x80; //uart mode
U0UCR = 0x02; //low start bit, high end bit
U0CSR |= 0x40;
HalUARTInit();
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_9600;
uartConfig.flowControl = FALSE;
uartConfig.flowControlThreshold = 0;
uartConfig.rx.maxBufSize = 0;
uartConfig.tx.maxBufSize = 0;
uartConfig.idleTimeout = 0;
uartConfig.intEnable = 0;
uartConfig.callBackFunc = NULL;
HalUARTOpen(HAL_UART_PORT_0,&uartConfig);

My code is under the line "//noam"

in the same file under function  I place the code:

static void performPeriodicTask( void )
{

//noam
HalUARTWrite(HAL_UART_PORT_0, "Hello!\r\n", 8);

...

}

I trying to get the message with TeraTerm, But I don't get it. What can be the problem?

  • HalUARTInit will call HalUARTInitDMA or HalUARTInitISR depends on your project (define HAL_UART_DMA or HAL_UART_ISR). PERCFG will be reprogrammed in HalUARTInitDMA or HalUARTInitISR. I would suggest you to put HalUARTInit before the line //noam.

  • Thank you

    How can I know if my project

    simpleBLEPeripheral is HalUARTInitDMA or HalUARTInitISR

    and what the differences between them? 

    is HalUARTInitDMA refers to Rx,Tx,CT,RT ? 

    Thanks again

    Noam

  • 1. Put any character before HalUARTInitDMA(); and compile the project. If there is compiling error, it means that you are using DMA mode. In the contrast, you uses ISR.

    2. You can google UART DMA or ISR and there are lots of references.

    3. No

  • Thanks again

    1. In which file and which location i enable the HAL_UART_DMA or HAL_UART_ISR ?

    Just to remind you, I am using the simpleBLEPeripheral which is not enabled by default.

    2. Which kind of UART more suitable to work with tremina (such a TeraTerm) DMA or ISR?

    Noam

  • When I search in files (project simpleBLEPeripheral) any HAL_UART_SPI or HAL_UART_DMA

    I don't find it is defined. Where should i defined it? And in which files the definition of it exist?

    Thanks

    Noam

  • It is defined in hal_board_cfg.h.

  • Ok. I find this file:

    Where I need to configure the keyfob to work with UART DMA or SPI?


    /* Set to TRUE enable UART usage, FALSE disable it */
    #ifndef HAL_UART
    #if (defined ZAPP_P1) || (defined ZAPP_P2) || (defined ZTOOL_P1) || (defined ZTOOL_P2)
    #define HAL_UART TRUE
    #else
    #define HAL_UART FALSE
    #endif
    #endif

    #if HAL_UART
    // Always prefer to use DMA over ISR.
    #if HAL_DMA
    #ifndef HAL_UART_DMA
    #if (defined ZAPP_P1) || (defined ZTOOL_P1)
    #define HAL_UART_DMA 1
    #elif (defined ZAPP_P2) || (defined ZTOOL_P2)
    #define HAL_UART_DMA 2
    #else
    #define HAL_UART_DMA 1
    #endif
    #endif
    #ifndef HAL_UART_ISR
    #define HAL_UART_ISR 0
    #endif
    #else
    #ifndef HAL_UART_ISR
    #if (defined ZAPP_P1) || (defined ZTOOL_P1)
    #define HAL_UART_ISR 1
    #elif (defined ZAPP_P2) || (defined ZTOOL_P2)
    #define HAL_UART_ISR 2
    #else
    #define HAL_UART_ISR 1
    #endif
    #endif
    #ifndef HAL_UART_DMA
    #define HAL_UART_DMA 0
    #endif
    #endif

    // Used to set P2 priority - USART0 over USART1 if both are defined.
    #if ((HAL_UART_DMA == 1) || (HAL_UART_ISR == 1))
    #define HAL_UART_PRIPO 0x00
    #else
    #define HAL_UART_PRIPO 0x40
    #endif

    #else
    #define HAL_UART_DMA 0
    #define HAL_UART_ISR 0
    #endif

    #if !defined HAL_UART_SPI
    #define HAL_UART_SPI 0
    #endif

    #ifdef __cplusplus
    }
    #endif

    #endif /* HAL_BOARD_CFG_H */

  • You can define HAL_UART in C/C++ preprocessor define of project options. DMA is default when you define HAL_UART.

  • Ok, I think i miss something

    1. I defined hal_uart.c as well:

    void HalUARTInit(void)
    {

    PERCFG |= 0x01; //usart0 alt.2
    U0GCR = 8;
    U0BAUD = 59;
    U0CSR = 0x80; //uart mode
    U0UCR = 0x02; //low start bit, high end bit
    U0CSR |= 0x40;

    halUARTCfg_t uartConfig;
    uartConfig.configured = TRUE;
    uartConfig.baudRate = HAL_UART_BR_9600;
    uartConfig.flowControl = FALSE;
    uartConfig.flowControlThreshold = 0;
    uartConfig.rx.maxBufSize = 0;
    uartConfig.tx.maxBufSize = 0;
    uartConfig.idleTimeout = 0;
    uartConfig.intEnable = 0;
    uartConfig.callBackFunc = NULL;
    HalUARTOpen(HAL_UART_PORT_0,&uartConfig);

    #if (HAL_UART_DMA && HAL_UART_SPI) // When both are defined, port is run-time choice.
    if (HAL_UART_PORT)
    {
    HalUARTInitSPI();
    }
    else
    {
    HalUARTInitDMA();
    }
    #else
    #if HAL_UART_DMA
    HalUARTInitDMA();
    #endif
    #if HAL_UART_ISR
    HalUARTInitISR();
    #endif
    #if HAL_UART_SPI
    HalUARTInitSPI();
    #endif
    #if HAL_UART_USB
    HalUARTInitUSB();
    #endif
    #endif
    }

    2. Now under simpleBLEPeripheral.c , function void SimpleBLEPeripheral_Init( uint8 task_id )

    I called void HalUARTInit(void)

    as i wrote above under "//noam"

    3. in function static void performPeriodicTask( void )

    I wrote

    HalUARTWrite(HAL_UART_PORT_0, "Hello!\r\n", 8);

    Do I miss something? all i want is to get the word "Hello" in my TeraTerm through pin T1_5 which is pin 2 of additional test pin of the keyfob (the small connector)

    I also connected a scope to see if i can see any signal. and nothing.

    Please review my configuration under HalUARTInit, is there something i missed?