/* * On My Own Technology private Limited * date : 25-3-2019 * Author : Vinay Vishwakarma * Last modified : 19-3-2019 * project : speed ver 6_1 * Hardware : CC3220. * OS : TI - rtos ( Sys/BIOS). * File : TestSpi.c */ /* For usleep() */ #include <unistd.h> #include <stdint.h> #include <stddef.h> #include <stdio.h> /* Driver Header file*/ #include <ti/drivers/GPIO.h> #include <ti/drivers/SPI.h> #include <ti/display/Display.h> #include <ti/display/DisplayUart.h> #include <ti/display/DisplayExt.h> #include <ti/display/AnsiColor.h> /* POSIX Header file*/ #include <pthread.h> #include <semaphore.h> #include <unistd.h> /* Board Header file */ #include "Board.h" #define THREADSTACKSIZE (1024) static Display_Handle display; static SPI_Handle masterSpi; uint8_t masterRxBuffer[3] = {0,0,0}; uint8_t masterTxBuffer[3]; uint16_t value, value2; uint32_t time1 = 1; /* semaphore declaration */ sem_t masterSem; /* * callback function for spi */ //void myCallbackFnx(SPI_Handle masterSpi,SPI_Transaction *transaction) //{ // sem_post(&masterSem); // //printf("semaphore posted"); //} void *masterThread(void *arg0) { SPI_Params spiParams; SPI_Transaction transaction; //uint32_t i; bool transferOk; // int32_t status; // status = sem_init(&masterSem,0,0); // if (status != 0) // { // Display_printf(display,0,0,"Error Creating masterSem"); // } SPI_Params_init(&spiParams); spiParams.frameFormat = SPI_POL0_PHA0; spiParams.transferMode = SPI_MODE_BLOCKING; spiParams.bitRate = 10000; //spiParams.transferCallbackFxn = myCallbackFnx; spiParams.dataSize = 8; // transaction.arg = masterSem; masterSpi = SPI_open(Board_SPI0, &spiParams); if (masterSpi == NULL) { Display_printf(display,0,0,"Error initializing master SPI"); while(1); } else { Display_printf(display,0,0,"Master SPI initialized "); } while (1) { masterTxBuffer[0] = 0x01; masterTxBuffer[1] = 0x80; masterTxBuffer[2] = 0x00; value = 0x00; value2 = 0x00; transaction.count = 3; transaction.txBuf = masterTxBuffer; transaction.rxBuf = masterRxBuffer; transferOk = SPI_transfer(masterSpi,&transaction); if(transferOk) { // Display_printf(display,0,0,"Transfer Successful"); value2 = ((masterRxBuffer[1]<<8)&0x0300); value = (value2|masterRxBuffer[2]); // Display_printf(display,0,0,"The converted value is %d ",value); Display_printf(display,0,0," the buffer value are value is %x: %x :%x", masterRxBuffer[0],masterRxBuffer[1],masterRxBuffer[2]); // sem_wait(&masterSem); } else { Display_printf(display,0,0,"Transfer unsuccessful"); } sleep(1); } } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { /* 1 second delay */ uint32_t time1 = 1; pthread_t thread0; pthread_attr_t attrs; struct sched_param priParam; int retc; int detachedState; pthread_attr_init(&attrs); detachedState = PTHREAD_CREATE_DETACHED; priParam.sched_priority = 1; retc = pthread_attr_setschedparam(&attrs,&priParam); retc |= pthread_attr_setdetachstate(&attrs,detachedState); retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE); if (retc != 0) { printf("imuThread Hard fault : entering while(1) forever\n"); while(1); } retc = pthread_create(&thread0, &attrs,masterThread , NULL); if (retc != 0) { printf("imuThread Hard fault : entering while(1) forever\n"); while(1); } else { printf("Task one created successfully "); } /* Call driver init functions */ GPIO_init(); SPI_init(); Display_init(); display = Display_open(Display_Type_UART, NULL); if (display == NULL) { /* Failed to open display driver */ printf("display initialization failed "); while (1); } /* Configure the LED pin */ GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* Turn on user LED */ GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON); while (1) { sleep(time1); GPIO_toggle(Board_GPIO_LED0); printf("i am printing on console\n"); } }
above is my code for spi transaction for mcp3008 ADC, by using this code i am unable to receive the data from the ADC