Created
July 6, 2011 13:20
-
-
Save shahpoojan/1067201 to your computer and use it in GitHub Desktop.
BitCloud : Read and Write on USART
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /**************************************************************************//** | |
| \file myusart.c | |
| \application to read data from USART. | |
| \the application turns on the Red light, if 'a' is received, Green Light if | |
| \'b' is received and Yellow light for anything else | |
| ******************************************************************************/ | |
| #include <appTimer.h> | |
| #include <zdo.h> | |
| #include <myusart.h> | |
| #include <usart.h> | |
| #define RX_BUFFER_SIZE 10 | |
| #define TX_BUFFER_SIZE 10 | |
| #define LENGTH 1 | |
| #define appOpenLeds() BSP_OpenLeds() | |
| #define appCloseLeds() BSP_CloseLeds() | |
| #define appOnLed(id) BSP_OnLed(id) | |
| #define appOffLed(id) BSP_OffLed(id) | |
| #define appToggleLed(id) BSP_ToggleLed(id) | |
| HAL_UsartDescriptor_t usart; | |
| static uint8_t Rx_Buffer[RX_BUFFER_SIZE]; | |
| static uint8_t Tx_Buffer[TX_BUFFER_SIZE]; | |
| /****************************************************************************** | |
| Description: USART Recieve Callback | |
| Parameters: none | |
| Returns: nothing | |
| ******************************************************************************/ | |
| void usartRcvd() | |
| { | |
| appOffLed(LED_RED); | |
| appOffLed(LED_GREEN); | |
| appOffLed(LED_YELLOW); | |
| uint8_t usartRecieveBuffer; | |
| uint8_t errBuffer = 'e'; | |
| uint16_t length; | |
| HAL_ReadUsart(&usart,&usartRecieveBuffer,LENGTH); | |
| if(usartRecieveBuffer == 'a'){ | |
| appOnLed(LED_RED); | |
| } | |
| else if(usartRecieveBuffer == 'b'){ | |
| appOnLed(LED_GREEN); | |
| } | |
| else{ | |
| appOnLed(LED_YELLOW); | |
| } | |
| } | |
| void Usart_Init() | |
| { | |
| usart.tty = USART_CHANNEL_1; | |
| usart.mode = USART_MODE_ASYNC; | |
| usart.baudrate = USART_BAUDRATE_19200; | |
| usart.dataLength = USART_DATA8; | |
| usart.parity = USART_PARITY_NONE; | |
| usart.stopbits = USART_STOPBIT_1; | |
| usart.rxBuffer = Rx_Buffer; | |
| usart.rxBufferLength = RX_BUFFER_SIZE; | |
| usart.txBuffer = Tx_Buffer; | |
| usart.txBufferLength = TX_BUFFER_SIZE; | |
| usart.rxCallback = usartRcvd; | |
| usart.txCallback = NULL; | |
| usart.flowControl = USART_FLOW_CONTROL_NONE; | |
| HAL_OpenUsart(&usart); | |
| } | |
| /******************************************************************************* | |
| Description: application task handler. | |
| Parameters: none. | |
| Returns: nothing. | |
| *******************************************************************************/ | |
| void APL_TaskHandler(void) | |
| { | |
| Usart_Init(); | |
| appOpenLeds(); // Enable LEDs | |
| uint8_t usartRecieveBuffer; | |
| HAL_WriteUsart(&usart,"Hello",strlen("Hello")); | |
| appOnLed(LED_RED); | |
| appOnLed(LED_YELLOW); | |
| appOnLed(LED_GREEN); | |
| } | |
| /******************************************************************************* | |
| Description: just a stub. | |
| Parameters: are not used. | |
| Returns: nothing. | |
| *******************************************************************************/ | |
| void ZDO_MgmtNwkUpdateNotf(ZDO_MgmtNwkUpdateNotf_t *nwkParams) | |
| { | |
| nwkParams = nwkParams; // Unused parameter warning prevention | |
| } | |
| /******************************************************************************* | |
| Description: just a stub. | |
| Parameters: none. | |
| Returns: nothing. | |
| *******************************************************************************/ | |
| void ZDO_WakeUpInd(void) | |
| { | |
| } | |
| #ifdef _BINDING_ | |
| /*********************************************************************************** | |
| Stub for ZDO Binding Indication | |
| Parameters: | |
| bindInd - indication | |
| Return: | |
| none | |
| ***********************************************************************************/ | |
| void ZDO_BindIndication(ZDO_BindInd_t *bindInd) | |
| { | |
| (void)bindInd; | |
| } | |
| /*********************************************************************************** | |
| Stub for ZDO Unbinding Indication | |
| Parameters: | |
| unbindInd - indication | |
| Return: | |
| none | |
| ***********************************************************************************/ | |
| void ZDO_UnbindIndication(ZDO_UnbindInd_t *unbindInd) | |
| { | |
| (void)unbindInd; | |
| } | |
| #endif //_BINDING_ | |
| /**********************************************************************//** | |
| \brief Main - C program main start function | |
| \param none | |
| \return none | |
| **************************************************************************/ | |
| int main(void) | |
| { | |
| SYS_SysInit(); | |
| for(;;) | |
| { | |
| SYS_RunTask(); | |
| } | |
| } | |
| //eof myusart.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment