Problem with threads

29 Jan 2014

Hi

I am creating an occupancy detection system using mbed. What i have to do is to have to separate threads one for occupancy detection and the other for receiving data from the base station. below is the code of my main function and thread function.

void recv_thread(void const *args) { while (true) {

pc.printf("In thread function\r\n"); RxData_RF();

Thread::wait(200); Thread::yield();

} } Thread which is receiving the data from the base station and other nodes////

i want to have the occupancy information calculated in parallel and transmitted//

Main Function(thread) //

int main() {

spi.format(8,0); spi.frequency(1000000); reset(); init_CC2500();

Thread thread(recv_thread);

while(1) {

occ=getoccupancy(); function that reads values of different sensors and calculate occupancy. occcheck(); gettemp(); makepack(); pc.printf("transmitting data \r\n"); TxData_RF(datatosend); transmitting the data across to base station Thread::wait(200); }

}

My main() thread 1 or two times and does not run after that .. what can the problem be ?

29 Jan 2014

Use <<code>> and <</code>>, otherwise it isn't readable.

First try to figure out of the TxData_RF function, or the getoccupancy function is the one which stops your thread. (Comment one of them out, check if it still works). And still try to add some printfs to figure out where it stops exactly. Then when you know that you can try to figure out why it stops.