Other Parts Discussed in Thread: CC3220SF
Hi community,
I'm working on SPI based EEPROM write read operation.
Using CC3220SF-LAUNCHXL Rev.A to write and read operation to/from the 25LC1024 SPI based EEPROM with the help of simplelink cc32xx sdk 6.10.00.05
Searched for NORTOS example code for SPI based EEPROM operation, did not found if find any Example(s) code for SimpleLink CC3220SF to EEPROM read write operation please do share.
So i modified the TI RTOS bases SPI master example code as per requirement.
After that modification when tried to write data 0xAA to the EEPROM and read back from the same address (0x0010FF) i'm getting 0xFF as output i changed address to 0x001000 then also same output. Can any one help me out to solve this.
The modified code as follows:
/* * ======== spi_eeprom.c ======== */ #include <stdint.h> #include <stdio.h> #include <stddef.h> #include <unistd.h> #include <string.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/SPI.h> /* Driver configuration */ #include "ti_drivers_config.h" #define SPI_MSG_LENGTH (8) unsigned char controllerRxBuffer[SPI_MSG_LENGTH]; unsigned char controllerTxBuffer[SPI_MSG_LENGTH]; /* EEPROM instructions */ #define EEPROM_WRITE_ENABLE (0x06) #define EEPROM_WRITE_DISABLE (0x04) #define EEPROM_READ (0x03) #define EEPROM_WRITE (0x02) #define EEPROM_ID (0xAB) SPI_Handle controllerSpi; SPI_Handle Init_SPI(void){ SPI_Params spiParams; //printf("SPI initiating\n"); SPI_Params_init(&spiParams); // Initialize SPI parameters spiParams.dataSize = 8; // 8-bit data size spiParams.frameFormat = SPI_POL0_PHA0; spiParams.bitRate = 1000000; controllerSpi = SPI_open(CONFIG_SPI_0, &spiParams); if (controllerSpi == NULL) { printf("Error initializing controller SPI\n"); } else { printf("SPI initialized\n"); } return controllerSpi; } int writeToEEPROM(uint32_t address, uint8_t* data, uint32_t dataSize) { SPI_Transaction spiTransaction; bool transferOK; printf("To write\n"); uint8_t tmp_txBuffer[SPI_MSG_LENGTH]; tmp_txBuffer[0] = EEPROM_WRITE_ENABLE; // EEPROM write enable latch tmp_txBuffer[1] = EEPROM_WRITE; // EEPROM write command tmp_txBuffer[2] = (address >> 16) & 0xFF; // Address MSB tmp_txBuffer[3] = (address >> 8) & 0xFF; // Address middle byte tmp_txBuffer[4] = address & 0xFF; // Address LSB tmp_txBuffer[5] = data; // data to be written to 25LC1024 strncpy((char *)controllerTxBuffer, tmp_txBuffer, sizeof(SPI_MSG_LENGTH)); memset((void *)controllerRxBuffer, 0, SPI_MSG_LENGTH); spiTransaction.count = SPI_MSG_LENGTH; spiTransaction.txBuf = (void *)controllerTxBuffer; spiTransaction.rxBuf = (void *)controllerRxBuffer; /* Toggle user LED, indicating a SPI transfer is in progress */ GPIO_toggle(CONFIG_GPIO_LED_1); /* Perform SPI transfer */ transferOK = SPI_transfer(controllerSpi, &spiTransaction); if (transferOK) { printf("Master transmitted data: %x\n", *(char *)controllerTxBuffer); //printf("bufr address of transmitted data: %#x\n", controllerTxBuffer); } else { printf("Unsuccessful SPI transfer"); return -1; } return 0; } int readFromEEPROM(uint32_t address, uint8_t* receiveBuffer, uint32_t dataSize) { printf("To read\n"); // Prepare the read command and address SPI_Transaction spiTransaction; bool transferOK; uint8_t tmp_txBuffer[SPI_MSG_LENGTH]; tmp_txBuffer[0] = EEPROM_READ; // Read command tmp_txBuffer[1] = (address >> 16) & 0xFF; // Address MSB tmp_txBuffer[2] = (address >> 8) & 0xFF; // Address middle byte tmp_txBuffer[3] = address & 0xFF; // Address LSB tmp_txBuffer[4] = 0xBB; // dummy data strncpy((char *)controllerTxBuffer, tmp_txBuffer, sizeof(SPI_MSG_LENGTH-1)); memset((void *)controllerRxBuffer, 0, SPI_MSG_LENGTH-1); spiTransaction.count = SPI_MSG_LENGTH - 1; // Read command + address + dummy with dataSize spiTransaction.txBuf = (void *)controllerTxBuffer; spiTransaction.rxBuf = (void *)controllerRxBuffer; /* Toggle user LED, indicating a SPI transfer is in progress */ GPIO_toggle(CONFIG_GPIO_LED_1); /* Perform SPI transfer */ transferOK = SPI_transfer(controllerSpi, &spiTransaction); if (transferOK) { printf("Master received data: %x\n", *(char *)controllerRxBuffer); //printf("bufr address of received data : %#x\n", controllerRxBuffer); } else { printf("Unsuccessful SPI transfer"); return -1; } return 0; } void *mainThread(void *arg0) { uint8_t writeData[] = {0xAA}; // Data to write to the EEPROM uint32_t address = 0x000010FF; // Address to write to and read from uint32_t dataSize = sizeof(writeData); // Size of data to write and read uint8_t receiveBuffer[dataSize]; /* Call driver init functions. */ GPIO_init(); SPI_init(); /* Configure the LED pins */ GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_setConfig(CONFIG_GPIO_LED_1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); Init_SPI(); /* Turn on user LED */ GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON); // Write data to the EEPROM writeToEEPROM(address, writeData, dataSize); // Read data from the EEPROM readFromEEPROM(address, receiveBuffer, dataSize); SPI_close(controllerSpi); printf("\nDone"); }
Output which i got for the above code:
To write
Master transmitted data: 6
To read
Master received data: ff
Here is the pin configuration of SPI for SimpleLink board
Hardware is configured as follows:
Simple Link | 25LC1024 |
SCLK | SCK |
MISO | SO |
MOSI | SI |
SS | CS bar |
3V3 | VCC |
GND | VSS |
Thanks and Regards,
Ajaykumar V