Other Parts Discussed in Thread: CC2650
I am currently working on a project where I am using a CC2650 Launchpad with Bluetooth Low Energy to allow communication between a phone and a MSP430. We are having issues grabbing data that the CC2650 receives from the phone and then sending that same data over UART to the MSP430. We can send data from the phone to the MSP430 one time through the CC2650, but that data never updates when the phone sends new data to the CC2650.
We started the project using the ProjectZero example for the phone to bluetooth chip portion and added in code from uartecho_CC2650_LAUNCHXLL_TI.... to get the UART functionality. We have identified a spot in the project_zero.c file where we think the calls to our UART read and write need to happen, but are not having any luck getting the code to send the new data after the initial data. Attached are screenshots of the code. We utilize the ProjectZero_taskFxn() call from the projectzero construct to use the for(;;) loop given in the example (first code snippet below). The second image uses the user_processApplicationMessage(psMg) call in project_zero.c. This eventually leads to the third image which calls the user_DataService_ValueChangeHandler() where we have implemented a modified version of the uart_echo example and labeled the modified code UART_MCU(). The function then calls the second code snippet below labeled UART_MCU() and we attempt to write and read from an msp430 using uart. The current set up allows us to read continuously (due to the while loop) and also write new data from the phone to the msp430 only once. However, we must write first in order to read any data from the msp430 since we have implemented our uart call in a place in project_zero.c where the program waits for an incoming message from the phone. We know this is not the correct way to implement our functionality logically, however, we have not been able to successfully build when placing or UART implementation elsewhere. Do you have any suggestions on where we can place our UART implementation so that we can read and write continuously from the msp430 and a mobile application?
P.S. We are not using the task_construct in UART since we did not see any changes with it implemented, however ,we assume this may be a problem as well and can easily implement it back in.
static void ProjectZero_taskFxn(UArg a0, UArg a1)
{
// Initialize application
ProjectZero_init();
//UART_Read();
//static uint8_t received_string[DS_STRING_LEN] = {0};
//UART_Start(received_string);
// Application main loop
for (;;)
{
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
// ICall_signal() function is called onto the semaphore.
ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
//UART_Read();
if (errno == ICALL_ERRNO_SUCCESS)
{
ICall_EntityID dest;
ICall_ServiceEnum src;
ICall_HciExtEvt *pMsg = NULL;
// Check if we got a signal because of a stack message
if (ICall_fetchServiceMsg(&src, &dest,
(void **)&pMsg) == ICALL_ERRNO_SUCCESS)
{
uint8 safeToDealloc = TRUE;
if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity))
{
ICall_Stack_Event *pEvt = (ICall_Stack_Event *)pMsg;
// Check for event flags received (event signature 0xffff)
if (pEvt->signature == 0xffff)
{
// Event received when a connection event is completed
if (pEvt->event_flag & PRZ_CONN_EVT_END_EVT)
{
// Try to retransmit pending ATT Response (if any)
ProjectZero_sendAttRsp();
}
}
else // It's a message from the stack and not an event.
{
// Process inter-task message
safeToDealloc = ProjectZero_processStackMsg((ICall_Hdr *)pMsg);
}
}
if (pMsg && safeToDealloc)
{
ICall_freeMsg(pMsg);
}
}
// Process messages sent from another task or another context.
while (!Queue_empty(hApplicationMsgQ))
{
app_msg_t *pMsg = Queue_dequeue(hApplicationMsgQ);
// Process application-layer message probably sent from ourselves.
user_processApplicationMessage(pMsg);
// Free the received message.
ICall_free(pMsg);
}
}
}
}
extern void UART_MCU(uint8_t *received_string)
{
char input[3] = {0};
//char output[3] = {0};
//int num_bytes =0;
//int inc = 0;
int len_read = (sizeof(input)/sizeof(char));
int num_bytes = 0;
//int len = (sizeof(received_string)/sizeof(uint8_t));
UART_Handle uart;
UART_Params uartParams;
//Create a UART with data processing off.
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
//uartParams.readMode = UART_MODE_CALLBACK;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 9600;
uart = UART_open(Board_UART0, &uartParams);
uint8_t *write_string;
while(1)
{
write_string = received_string;
if (uart == NULL)
{
;//System_abort("Error opening the UART");
}
memset(input,0,sizeof(input));
__delay_cycles(1000000);
if(num_bytes= UART_read(uart, &input, len_read))
{
if(num_bytes == UART_ERROR)
{
printf("Error reading from MSP430\n");
}
else
{
// Initalization of characteristics in Data_Service that can provide data.
DataService_SetParameter(DS_STRING_ID, sizeof(input), input);
}
}
if(num_bytes= UART_write(uart,write_string, 3))
{
if(num_bytes == UART_ERROR)
{
printf("Error writing to MSP430\n");
}
//DataService_SetParameter(DS_STREAM_ID, DS_STREAM_LEN, initVal);
}
memset(input,0,sizeof(input));
}
}