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?