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.

CC2530 HEX printout

Other Parts Discussed in Thread: CC2530, Z-STACK

Hi Guys,

I working to integrate my core dimmer to an exchange, device that working well with zero crossing detector, via Uart using an existent protocol. 

My device running over Zstack Z-Stack Home 1.2.2a.44539 referenced to CC2530 HA Sample light switch project.

I have started my dimmer with this configuration:

Hal_board_cfg: CC2530EB

Compiler options for Uart settings: ISR_KEYINTERRUPT, HAL_UART=TRUE, HAL_UART_ISR=1 and HAL_UART_DMA=FALSE

Settings in my C file:

UART Start

// This app is part of the UART Init - Port 0 P0_2/P0_3 RX/TX
void initUart0(halUARTCBack_t pf)
{
HalUARTInit();
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_115200;
uartConfig.flowControl = FALSE; // need to configure it as No flow control in Remote Terminal.
uartConfig.flowControlThreshold = 48;
uartConfig.rx.maxBufSize = 128;
uartConfig.tx.maxBufSize = 128;
uartConfig.idleTimeout = 6;
uartConfig.intEnable = TRUE;
uartConfig.callBackFunc =pf;
//start UART
//assumes no issues with starting UART
(void)HalUARTOpen(HAL_UART_PORT_0,&uartConfig);

}
void uart0RxCb( uint8 port, uint8 event )
{
uint8 ch;
while (Hal_UART_RxBufLen(port))
{
// Read one byte from UART to ch
HalUARTRead (port, &ch, 1);
}
}

My device init:

initUart0(uart0RxCb);

My new function that is not working well:

/*********************************************************************
* @fn zclTTa0003_UartSEND
*

*/
void uart0Send(uint8* uartTxBuffer, uint16 uartTxBufLength)
{

// Clear any pending TX interrupt request (set U0CSR.TX_BYTE = 0).
U0CSR |= 0x80;

// Loop: send each UART0 sample on the UART0 TX line.
for (uartTxIndex = 0; uartTxIndex < uartTxBufLength; uartTxIndex++)
{
U0DBUF = uartTxBuffer[uartTxIndex];
while(! (U0CSR & 0x80) );
U0CSR &= ~0x80;
}
}

My new function called in on/off CMD:

if ( cmd == COMMAND_ON )
{
zclTTa0003_OnOff = LIGHT_ON;

#ifdef ZCL_MONITOR
//Output "UART debug output" to UART Port0
HalUARTWrite( HAL_UART_PORT_0, "Light is ON", (byte)osal_strlen("Light is ON"));
#endif

}
// Turn off the light Written ASA
else if ( cmd == COMMAND_OFF )
{
zclTTa0003_OnOff = LIGHT_OFF;

#ifdef ZCL_MONITOR
//Output "UART debug output" to UART Port0
uart0Send(uartTxBuffer, SIZE_OF_UART_TX_BUFFER);
#endif

The existent protocol have follow structure:

My dimmer (Master):

Exchange device (Slave): 

Frame Format Structure:

The word sent by Master (my dimmer device):

When: AABB is a Duty Cycle value to setup the PWM Level in a exchange board. 

I have in my mind to cut the word in 2 parts, 1st 055C010000000000000000, 2st AABB0000000000000000000000000000 and handling duty cycle in the 2st part. After it to merge in a function to send a complete word. 

I need to build a SEND UART function, to send the word. I study UART Hal API and Didn´t find anything command to do that.

Before to send a HEX values in a new function I starting to test with string text, but i is not working, when my device call this new function stop to work. 

Anybody have an idea how to build a function to send the word above?

  • Why don’t you use API HalUARTWrite in your uart0Send instead of using register operations directly? You can refer to sunmaysky.blogspot.com/.../how-to-use-two-uart-ports-in-cc2530-z.html for CC2530 UART usage in Z-Stack.
  • Hi Mr YK,

    I got to handle the HalUARTWrite API, but I didn´t see how to concatenate the 2 or 3 parts to form a Protocol Word. 

    Byte [0]: STX – fixed value 0x05.
    Byte [1]: LEN – Frame length, equation is N + 3, where N is total number of bytes of
    payload.
    Bytes [2] .. [(N – 1)]: PAYLOAD – All important data.

    For example:

    051C010000000000000000AABB0000000000000000000000000000

    1st part: (fixed value) - 051C01000000000000000

    when: 0x05 fixed part, 1C Frame LEN and 01000000000000000 complement (also fixed).

    2st part: (duty Cycle) - AABB (variable part) - 17FC represent 10%

    3rd part: (tail) - 0000000000000000000000000000

    I just need to change duty cycle value.

    BR

    Alex

    021C010000000000000000AABB0000000000000000000000000000
  • I suppose you can create two buffers and use memory copy to make it.

  • Hi Mr YK,

    I working on HalUart API to send a world to exchange device. But HalUARTWrite not working with Char type.  Would you give an idea to fix it?

    #define SIZE_OF_UART_RX_BUFFER 2
    #define SIZE_OF_UART_TX_BUFFER SIZE_OF_UART_RX_BUFFER
    char smartdata1[]={"055"};
    char smartdata2[]={"1C"};
    char smartdata3[]={"000000000000000000"};
    char smartdata4[]={"0BC0"};
    char smartdata5[]={ "0000000000000000000000000000"};

    To test HalUARTWrite i start to send smartdata1[] and i got error during compiler procedure.

    HalUARTWrite( HAL_UART_PORT_0, smartdata1[0], (byte)osal_strlen("055"));

    Compiler Error: 

    Error[Pe167]: argument of type "char" is incompatible with parameter of type "uint8 *" C:\Texas Instruments\Z-Stack Home 1.2.2a.44539\Projects\zstack\HomeAutomation\TEHA0003\Source\zcl_TTa0003.c 1160

  • Can you elaborate what you mean to do with HalUARTWrite? Why do you use  (byte)osal_strlen("055") as 3rd parameter in HalUARTWrite?

  • Hi Mr YK, thanks a lot for your assistance!

    I would like to form a word to starting communication via UART w exchange device, as I wrote:
    051C010000000000000000AABB0000000000000000000000000000
    I planning to divide it in 5 parts, because an unique part that is variable (duty cycle)
    05 - fixed value ( master to slave)
    1c - fixed value (length)
    010000000000000000 - fixed value (prefix)
    AABB - duty cycle - unique variable part
    0000000000000000000000000000 - fixed part (sufix)

    I used HalUart API trough HalUartWrite but is incompatible with my string structure above:
    I used 3rd parameter to fill the length according defined in HalUartWrite partern.

    HalUARTWrite( HAL_UART_PORT_0, "Light is OFF", (byte)osal_strlen("Light is OFF"));

    Do you can advise me how to make an working around to fix it?
  • You cannot use osal_strlen to get correct length when there’s hex 0 in your string array.
  • Hi Mr Yk,

    Thanks a lot, i had success to send string via HalUart API, as you see bellow. My error was during initializing string and also when I called HalUART API:

    char smartdata2[]={'1','C','\0'};
    char smartdata3[]={'0','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','\0'};
    char smartdata4[]={'1','7','F','C','\0'};
    char smartdata5[]={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','\0'};

    HalUARTWrite( HAL_UART_PORT_0, smartdata1,SIZE_OF_UART_RX_BUFFER1);
    HalUARTWrite( HAL_UART_PORT_0, smartdata2,SIZE_OF_UART_RX_BUFFER1);
    HalUARTWrite( HAL_UART_PORT_0, smartdata3,SIZE_OF_UART_RX_BUFFER2);
    HalUARTWrite( HAL_UART_PORT_0, smartdata4,SIZE_OF_UART_RX_BUFFER3);
    HalUARTWrite( HAL_UART_PORT_0, smartdata5,SIZE_OF_UART_RX_BUFFER4);

    To form the word I sent each one string part, from master (CC2530) to slave (external exchange device), but always in the tail, or last string, I seeing a "þA€" undesirable character or trash.

    I tried to include at the end of string array /n or /r but nothing worked!

    In addition I always see warning at each one string initialization, during compilation process:

    Warning[Pe167]: argument of type "char *" is incompatible with parameter of type "uint8 *" C:\Texas Instruments\Z-Stack Home 1.2.2a.44539\Projects\zstack\HomeAutomation\TEHA0003\Source\zcl_TTa0003.c 1233

    Do you have any idea to fix it?

    BR

    Alex

  • You can use cast to fix the compiling warning "argument of type "char *" is incompatible with parameter of type "uint8 *"".

  • Hi Mr YK,

    Would you can help me to understanding to working with Cast?

    I did it but is not working:

    //global variable:

    char smartdata2[]={'1','C','\0'};

    //without my file loop

    HalUARTWrite( HAL_UART_PORT_0, (uint8)smartdata2,SIZE_OF_UART_RX_BUFFER1);

    I still got this error: 

    Error[Pe167]: argument of type "uint8" is incompatible with parameter of type "uint8 *" C:\Texas Instruments\Z-Stack Home 1.2.2a.44539\Projects\zstack\HomeAutomation\TEHA0003\Source\zcl_TTa0003.c 1234

    Do you can help me, please?

    BR,

    Alex

  • You should use "(uint8*)" instead of "(uint8)". By the way, this is very fundamental C programming skill and I suggest you to study C programming more.

  • Hi Mr Yk,

    thanks a lot and sorry for my mistakes. I´m studying C to improve my knowledge!

    Right now my HAL API code to send characters is correctly:

    HalUARTWrite( HAL_UART_PORT_0, (uint8*)smartdata2,SIZE_OF_UART_RX_BUFFER1);

    And after it I'm not seeing any more warnings in my compiler!

    But in the tail still appear, always after the last string sent, stranger characters. As you see bellow,

    Do you have an idea what´s happening?

  • I suggest you to check if smartdata2 is the correct string size before you do HalUARTWrite.
  • Mr Yk,

    I make a double check and than see that the length string2 (last tring) i is correctly. I made two things to check it:

    1st - changed the output format from ASCII to ANSI (I used it in all those printouts), after it i can see better the wrong values at the end of strings.

    2 st - changed the string array initialization to 27, 28 and 29. as you see bellow nothing was change at the end of last string.

      

  • I suggest you to check those extra bytes in hex format to better understanding what they are.
  • Hi Mr YK, sorry for my delay. I had a travel this week!

    You can see attached the printout in hexadecimal.

  • Those bytes are sent from MT command. Try to disable MT_TASK from compile option.

  • Hi Mr YK,

    You are the best!!!!

    After I comment out MT_TASK, in compiler options as you advise me, worked...

    Thanks a lot!!!!!

      

  • Tks a lot Mr. Yk!