Part Number: MSP-EXP432P401R
Tool/software: TI-RTOS
I am using the latest 1.30.00.40 SDK. I loaded the I2C master and slave examples onto two LaunchPads and with no modifications everything works fine. But as soon as I add another thread on the slave side, the i2c communication breaks.
I don't know if I am just not initializing the new thread correctly, but I basically duplicated everything from the main thread. To make it simple, all the second thread does is blink the led.
Also, why doesn't usleep() or sleep() work? Whenever I call either of those, it seems like everything just halts.
Either thread works fine by itself, just not together. I hope it's just something silly that I'm overlooking because eventually I'll need two i2c slave threads, one i2c master thread (separate busses), and some other threads all running at the same time, and if I can't even do this simple thing, I'll have a problem. I already have the i2c master thread running good in another project and eventually will need to integrate everything together. One small step at a time...
Here is my modified main_tirtos.c from the slave example, all other files are unchanged:
/* * ======== main_tirtos.c ======== */ #include <stdint.h> #include <unistd.h> #include <ti/drivers/GPIO.h> /* POSIX Header files */ #include <pthread.h> /* RTOS header files */ #include <ti/sysbios/BIOS.h> /* Example/Board Header files */ #include "Board.h" extern void *mainThread(void *arg0); void *dummyThread(void *arg0); /* Stack size in bytes */ #define THREADSTACKSIZE 1024 void *dummyThread(void *arg0) { #define DELAY 1000000 int i; /* Call driver init functions */ GPIO_init(); while (1) { GPIO_toggle(Board_GPIO_LED0); //usleep(1000000); //doesn't work, why?? Led just stays on solid //sleep(1); //doesn't work either, why?? Led just stays on solid for(i=0; i<DELAY; i++) {} //silly delay } } /* * ======== main ======== */ int main(void) { pthread_t thread, dummy_Thread; pthread_attr_t pAttrs, dummy_pAttrs; struct sched_param priParam, dummy_priParam; int retc; int detachState; /* Call driver init functions */ Board_initGeneral(); /* Set priority and stack size attributes */ pthread_attr_init(&pAttrs); pthread_attr_init(&dummy_pAttrs); priParam.sched_priority = 1; dummy_priParam.sched_priority = 1; detachState = PTHREAD_CREATE_DETACHED; retc = pthread_attr_setdetachstate(&pAttrs, detachState); if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1); } retc = pthread_attr_setdetachstate(&dummy_pAttrs, detachState); if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1); } pthread_attr_setschedparam(&pAttrs, &priParam); pthread_attr_setschedparam(&dummy_pAttrs, &dummy_priParam); retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1); } retc |= pthread_attr_setstacksize(&dummy_pAttrs, THREADSTACKSIZE); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1); } retc = pthread_create(&thread, &pAttrs, mainThread, NULL); if (retc != 0) { /* pthread_create() failed */ while (1); } retc = pthread_create(&dummy_Thread, &dummy_pAttrs, dummyThread, NULL); if (retc != 0) { /* pthread_create() failed */ while (1); } BIOS_start(); return (0); }
Thanks.
Also, in another post, I saw mention of a POSIX workshop in the SimpleLink Academy for the 1.30 SDK, but could not find it.