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.

how to do UART transmission from keyfob to pc

Other Parts Discussed in Thread: CC2540

I want to transmit data from keyfob to pc..

i have attached my code here..

i modified keyfob demo example with uart application ..

can u tell me how to transmit data to PC..?...

i set the port1.4 &1.5 for tx and rx enable to connect pc using rs232 to usb cable 

 

 

 

  P1SEL = 0x30; // Configure Port 1 as GPIO, except P1.4 and 1.5for peripheral function for UART

  P1DIR = 0xFF; // All port 1 pins (P1.0-P1.7) as output

 

  P1 = 0;   // All pins on port 1 to low

 

  // initialize the ADC for battery reads

 

  HalUARTInit();

 

 

  //Initialize ADC with internal 1.25V set as reference

  HalAdcSetReference( HAL_ADC_REF_125V );

 

  // Read the ADC

  adc_read = HalAdcRead( HAL_ADC_CHANNEL_VDD, HAL_ADC_RESOLUTION_10 );

 

  /*****************************************************************************  

   *

   *  the ADC takes in one-third of VDD as its input and has a 1.25V reference

   *  An adc_read value of 0 corresponds to 0V at the ADC input, and a value

   *  of 511 corresponds to 1.25V at the ADC input (with 10 bit resolution).

   * 

   *  The CC2540 requires 2.0V at VDD to operate according to the specification.

   *  Therefore, we will define 2.0V as 0% battery level, and 3.0V as 100% battery

   *  level. Therefore the simple formula for battery percentage is:

   * 

   * (Battery Percentage) = ((Battery Voltage) - 2.0) * 100

   *

   * From a software standpoint, the following calculation can be used to get the

   *  battery percentage:

   *  

   * With a 3V battery, we can approximate percentage by multiplying the ADC result

   * by 375, dividing by 511, and subtracting that result by 200. The value will not

   * be exact, due to the rounding of integer values, but should be within one percent.

   *

   * For example, if the battery voltage is 2.7V, the battery percentage should

   * be 70% ((2.7-2.0)*100 = 70). The ADC input will be one-third of the input (0.9V).

   * This will result in an adc_read value of 367 (0.9/1.25 * 511 = 367). If we apply

   * the calculation used by the software:

   *

   * ( (367 * 375) / 511 ) - 200 = 69

   *

   * This is within one percent of the actual value of 70%.

   *

   */

 

  adc_read_times_375 = (uint32)adc_read * (uint32)(375);

  batteryLevel_current_read = (uint8) ( (adc_read_times_375 / (uint32)(511)) - (uint32)(200) );

 

  /*****************************************************************************

   *

   * in a discharging battery state, the battery level can still fluctuate up

   * and down slightly over time, so we only want to change the battery level attribute

   * if it has dropped.

   *

   */

 

  if( batteryLevel_current_read < batteryLevel )

    batteryLevel = batteryLevel_current_read;

 

  if( batteryLevel < BATTERY_LEVEL_CRITICAL_PCT )

    batteryState = BATTERY_STATE_CRITICAL_REPLACE_NOW;

  else

    batteryState = BATTERY_STATE_DISCHARGING;

    HalUARTWrite(1,&batteryLevel,1);

 

   osal_msg_send( HR_TaskID, &batteryLevel);

 

  // Update the Battery Profile

 // Battery_SetParameter( BATTERY_ATTR_LEVEL, sizeof ( uint8 ), &batteryLevel );

 // Battery_SetParameter( BATTERY_ATTR_STATE

 

 

 

  • In order to to use P1.4 and P1.5 for UART you will need to use Usart 0 alternative 2 by adding register set: 

    PERCFG |= 0x01;

    Also try

    P1DIR = 0xEF; //Set P1.4 to input, others to output 

    Note that P1.5 is TX and P1.4 is RX. See http:// www.ti.com/lit/swru191 for more information.

  • thanks for reply 

    i enable  p1.4 as i/p and p1.5 o/p ..

    if i connect p1.5 to serial cable to hyperterminal..

    i didn't get no data..

    can u send me the sample code for uart...

     

     

  • Based on the code you attached above, I believe you should also open the port before you write to the UART. This is done by the HalUARTOpen() function.

    For example, 

     

    halUARTCfg_t = config;

    config.configured = true;

    config.baudRate = HAL_UART_BR_38400;

    config.flowControl = false;

    config.flowControlThreshold = 64;

    config.idleTimeout = 6;

    config.rx.maxBufSize = 128;

    config.tx.maxBufSize = 128;

    config.intEnable = false;

    config.callBackFunc = NULL;


    HalUARTOpen(HAL_UART_PORT_1, &config);

     

    You can read more about this in the Hal Driver API, found in you BLE installation folder (..\Texas Instruments\BLE-CC2540\Documents\hal).

  • I have been trying to get the CC2540 mini DK key fob to communicate to a PC and ran into a lot of road blocks.  But I was finally able to get it running.  I am very new to embedded development so this might be obvious to everyone else but this is what I got stumped on.

    The CC2540 uses TTL to signal, you need to convert it to a rs232 signal using a chip like a MAX-232.

    The sample projects are missing the following preprocessor definitions

    HAL_UART
    HAL_UART_ISR=2
    HAL_UART_ISR_RX_MAX=250
    There is some confusion as to what HAL_UART_ISR should be set to...

    The HAL layer in the sample projects don't deal well with the UART.  
    The HAL set UART1 to ALT 2 which outputs to P1_6. P1_6 is connected the send to the speaker. Every time I wrote to the UART it beeped at me. :)
    I had to make about 10-20 changes in the HAL code to get the UART to work correctly. Maybe I have an old copy? I can give a more detailed description of the changes if people like.

    It took me forever to find the key fob layout schematic.  I had no idea which pins had which gpio on it.  the schematic is in swrr071a.zip.
  • I also had to disable power management.  I could write out to the serial port but reading from the serial port was spotty at best, until I turned off power management.  works great now.  There is probably a bad interupt mask somewhere in the code.

  • Nick L said:

    config.callBackFunc = NULL;

    Hi Nick,

    I am having trouble understanding how callBackFunc is set to a specific function, what is the syntax for doing so?

    Thanks,
    Alex

  • config.callBackFunc is a function pointer (taking 2 arguments?) if I remember correctly.

    So, if your callback function is

    void myCallBackFunction(uint8 a, uint8 b) { ... }

    , you map your callback function to the UART configuration like this:

    config.callBackFunc = &myCallBackFunction;

    The value of config.callBackFunc is the address where myCallBackFunction is stored.

    Br,
    ABO 

  • hi andrew , i am very interested in your solution to the problem
    above could share your solution with me, since ja thank