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 --> Arduino 2560 --> PC

Other Parts Discussed in Thread: CC2540, CC-DEBUGGER, MAX232, CC2541

HI.

I'm having a bachelor project which involves working with the TI cc2540 keyfob.

My project contains of getting the CC2540 to communicate with a Android Phone (Going for the MOTO RAZR)

Since setting this up isn't straight forward, i'm going slowly forward to try to understand the whole consept of the CC2540 is working. 

I have successfully managed to get the sample-project of Heart Rate provided by TI, and sending the dummy heart rate to the RAZR, and now i want to try to get the CC2540 to send data through an Arduino 2560 with UART, and monitoring what the Arduino gets from the CC2540 Keyfob. 

I'm using the UART1 configuration, which RX/TX should be on pin P0_5/P0_4 to the DEBUGGER pins if i'm not to wrong. :)

The Sample-code i have used is the SimpleBLEPeripheral.

On the Arduino side i use a simple code which should read on RX3 on the Arduino.

The Arduino code looks like this:



char c;

void setup()

{
Serial3.begin(57600);
Serial.begin(57600);
Serial.println("HELLO WORLD!");

}

void loop()
{
}

void serialEvent3()
{

if (Serial3.available() > 0)
{
c = Serial3.read();
Serial.println(c);
}

}


Now this is the part where i'm very unsecure on the procedure. 

I have tried to configure the code in SimpleBlePeripheral_Main.C.

The code that i think should work is something like this, but when i try to monitor over the Arduino i get no respone/data from the CC2540 Keyfob. 


int main(void)
{
/* Initialize hardware */
HAL_BOARD_INIT();

// Initialize board I/O
InitBoard( OB_COLD );

/* Initialze the HAL driver */
HalDriverInit();

/* Initialize NV system */
osal_snv_init();

/* Initialize LL */

/* Initialize the operating system */
osal_init_system();

HalUARTInit ();

halUARTCfg_t config;

config.configured = true;

config.baudRate = HAL_UART_BR_57600;

/*
config.flowControl = false;

config.flowControlThreshold = 64;
*/

config.idleTimeout = 6;

config.rx.maxBufSize = 128;

config.tx.maxBufSize = 128;

config.intEnable = true;

uint8 NAVN[31] = {
0x53, // 'S'
0x69, // 'i'
0x6d, // 'm'
0x70, // 'p'
0x6c, // 'l'
0x65, // 'e'
0x42, // 'B'
0x4c, // 'L'
0x45, // 'E'
0x50, // 'P'
0x65, // 'e'
0x72, // 'r'
0x69, // 'i'
0x70, // 'p'
0x68, // 'h'
0x65, // 'e'
0x72, // 'r'
0x61, // 'a'
0x6c, // 'l'
};

uint16 LOGONAVN = HalUARTWrite (HAL_UART_PORT_1, NAVN, 7);

CODE ETC -->


If anyone have suggestions it would be much appreciated. 

Michael. 

  • I would suggest connecting your BLE SoC to PC directly and focusing on AVR software after managing comms with PC.

    Regards,
    Maciej 

  • Hi MaciejKucia and thanks for replying. 

    Since my project is based on using the keyfob, i won't get any COM PORT on the keyfob using the CC-Debugger to the PC.(Also using the Arduino should not give me any problems, since i'm using the integrated Monitor GUI from the Arduino software)

    Although i could use the USB-dongle because this gives me a COM-PORT, but can i use the same functions on the USB-dongle as on the Keyfob? 

    Regards Michael

  • Obviously you need some kind of USB-UART converter that works with 3v3. I am not familiar with Arduino and I doubt you will get help with third-party tools on TI forums. I believe (might be wrong!) that Arduino runs on 5V therefore there is a good chance of damaging your keyfob when connecting to Arduino (without level shifting).

  • Hello Mikkemus,

    The KeyFob and the USB dongle contain identical CC2540 chips.  Any application you design on the KeyFob will work on the Dongle.  There are some differences in terms of how the projects are set up in relation to power management.  Other than than the differences are in the pins that are readily available on each board.

    For the UART interface, there is a sample project on the BLEwiki that called SerialApp that shows the correct way to set up the UART.

    You can go with the USB if the only thing the Adrino is doing is providing a COM connection.  Also,the CC2540 has a high performance 8051 which quite frankly, can do a lot.  The Thermometer example or the hostTestRelease project would be the projects to follow.  There is a GUI for the Thermomter available on the BLEWiki as well.

    The thing I like to point out to designers is that if you are going wireless, then go wireless.  The Razor has Wifi which you can setup to communicate with your PC.  Depending on your application, there may not be a need for the contoller to be connected to the PC at all.

    Thanks,

  • Hi .

    You are right. The Arduino sends out 5V as you said on the pins. I need something like MAX232 converter if im going to use it with Arduino. 

    I have now set this setup a little aside and focused more on trying to get this to work with Btool by using the USB-dongle, since i don't have the MAX232 convertert at the moment.


    Sincear, Michael 

  • Hi greenja. 

    I looked into the SerialApp, and i understand alot more now following this code, so thank you. :) 

    I took the code that looked crucial, and for me this was the SerialAppUtil.c + SerialAppUtil.h code. I implemented these files in the SimpleBlePeriperal project and included at the same places it was on the SerialApp project. It now compiles with success, but i get three warnings. You can see these HERE. (Don't know how serious these are) 

    The configurations on the SerialApp is as i want, with Baud-Rate = 57600 and without flowcontol. 

    Is this everything i need to get RX to work now, or do i have to define more in the code? 

    So onto the bTool application.


    The USB dongle is now flashed with the USBdongle_HostTestRelease_All.hex file. This is the only one which works for me. (When flashing with the other .hex files BTool won't give me a COM port.) 

    I can't seem to get the understanding on where/how i can check to see if RX on the keyfob sends the data over to the USB-dongle with bTool? 

    Is this suppose to happen when the USB-dongle and the keyfob are establishing connection, or do i have to write a characteristic value to get the keyfob to send me the RX data? 

    Sincear, Michael

  • Hello Mikemus,

    Glad to hear you are progressing.  Are you getting serial communication between you Adrino and the KeyFob?

    The warnings mean that you have defined the variables in you routine, but have never actually used them anywhere in your code.

    You should be able to do a simple LED toggle on successful reading of a character.  So if you are sending an 'A' the green led toggles and a '5' the Red led toggles.

    For BTool, you can go to the Adv Command tab and look at the registers for the serial port, or a memory location.  There should be some way of seeing the UART registers.  I don't have that information.

    Thanks,

  • Hi greenja. 

    I haven't got it working with Arduino yet, due to that my application still won't work correct. 

    So for now i'm just using through rs232 --> USB. 

    When debugging, it seems like the HalUARTinit(); don't get called from the hal_drivers. (IMG)

    When going into the code i find that it is THIS function that desides if HalUARTinit gets defined or not in the hal_board_cfg.h file.

    I have tested the code with turning the internal LED on, and this works, but using the TX/RX still dosen't work.

    You can see the code i have put in to test HERE. The uartconfig redirects to the serialAppUtil.h file as you can see HERE

    Someone have any idea why i cant read anything from the dongle?

    Sincear, Michael. 

  • If you are using the USB, you have to make sure it is defined in hal_board_cfg.h. 

    /* Set to TRUE enable UART usage, FALSE disable it */
    #ifndef HAL_UART
    #define HAL_UART TRUE
    #define HAL_UART_DMA  0
    #define HAL_UART_ISR  0
    #define HAL_UART_USB  1
    #endif

    #ifndef HAL_UART_DMA
    #define HAL_UART_DMA 0
    #endif
    #ifndef HAL_UART_ISR
    #define HAL_UART_ISR 0
    #endif

    #ifndef HAL_UART_USB
    # if HAL_UART
    #  define HAL_UART_USB 1
    # else
    #  define HAL_UART_USB 0
    # endif
    #endif

    In your code you can then poll the USB

      // Poll USB for data is using USB Dongle
      HalUARTPoll();
      if (USB_data_ready){
        HalUARTRead(HAL_UART_PORT_0,msg_buf1,cntr);
        HalUARTRx(msg_buf1, 8);
        USB_data_ready = 0;
      }

  • Thanks for quick answer greenja. Much appreciated. :)

    In my previous post i explained a little unclear.

    I'm still using the dongle, but using the tx/rx + GND to a level converter over to rs232 --> usb. (I have tested the level converter so this works.)

    Sincear, Michael. 

  • Hi again greenja.

    I started the whole project from scratch and used the serialAppUtil.h & .c files with the simpleBLEPeripheral project, and 

    i'm happy to announce that i finally got the TX to work, so it now sends over UART to the PC with a terminal program :) 

    Sincear, Michael.

  • Hello Mikkemus,

    We are all happy that you were successful.

    Did you send by configuring the Tx as RS232 as per the example or did you go through Tx to USB?

    You can verify the post so others can know a solution has been found.

    Thanks,

  • Under i provide my changes under so people can easy get TX working. :) 

    Note. This has only been done with simpleBLEPeripheral project and added serialapp project (serialappUtil.c & h file + hal_uart_dma.c) into simpleBLEPeripheral.

    In my case i used a level coneverter between the dongle and the RS232 connector. I will also test to check if it works with Arduino if someone would want to know. :) 

    The setup under is provided with: 

    - Baudrate = 9600.

    - 1 stop bit.

    - No flowcontrol.

    - Tx output pin on debug connectors is P0_3.  (Also remember to have same GND as level converter)

    I added this line in my main: 

    ************************************************

    /* UART CONFIG*/
    serialAppInitTransport();

    *************************************************

    Added in serialAppUtil.C (beneith HalUARTOpen() ) 

    *************************************************

    HalUARTWrite(SBP_UART_PORT, " this works", 11);

    *************************************************

    In hal_board_cfg.h i edited this function;

    ***********************************************

    #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

    **********************************************

    To this here:

    *********************************************

    /* Set to TRUE enable UART usage, FALSE disable it */
    #ifndef HAL_UART
    #define HAL_UART TRUE
    #endif

    *********************************************

    Finally i edited this in simpleBlePeropheral.c

    *************************************************

    HalLedSet(HAL_LED_1, HAL_LED_MODE_ON );

    // 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 = 0x08; // Configure Port 0 as GPIO, expept for P0.4
    P1SEL = 0; // Configure Port 1 as GPIO
    P2SEL = 0; // Configure Port 2 as GPIO

    P0DIR = 0xF4; // Port 0 pins P0.0 P0.1 (buttons) and P0.3 as input(RX),
    // 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)
    HalLedSet(HAL_LED_1, HAL_LED_MODE_OFF);
    //YELLOW LIGHT OFF!
    HalLedSet(HAL_LED_2, HAL_LED_MODE_ON);
    //RED LIGHT ON!

    ****************************************************

    Sincear, Michael. 

  • Hi mikkemus,

    Can you send me the hardware the way you connect because I am try the code just like you since last month  but not getting success.

    1. Which device you use CC2540 or CC2541?.

    2. When we program CC2540 with BLE_Perifaral.c. then plug device in PC. it will not detect. i can't understand why it is happen.

    Most confusing part for me that where i have to initialize the uart and How?

    my email address is : rahulhgce@gmail.com.

    Please if possible can we  talk on skype.


    please reply as soon as possible.

    if possible can you send me all files which you change for uart communication.