Tool/software: Code Composer Studio
Hello
I have issues using SSIDataGet() and the advanced mode SSI_ADV_MODE_READ_WRITE, I try to read the manufacturer ID of FT800 but I don't know why it need send the read function many times becouse the first value is not correct.
I tried to using another GPIO (e.g. PORTJ GPIO_PIN_2) as CS instead of Fss and the things improved a little bit but was not the solution
the FT800 ID is 0x7C and I get this values:
*** SSI_0 & UART_0 done ***
Dato8 Addr= 0x102400 Read= 0x42
Dato8 Addr= 0x102400 Read= 0x4a
Dato8 Addr= 0x102400 Read= 0x43
Dato8 Addr= 0x102400 Read= 0x42
Dato8 Addr= 0x102400 Read= 0x4a
Dato8 Addr= 0x102400 Read= 0x43
Dato8 Addr= 0x102400 Read= 0x42
Dato8 Addr= 0x102400 Read= 0x7c
Dato8 Addr= 0x102400 Read= 0x4a
Dato8 Addr= 0x102400 Read= 0x43
Dato8 Addr= 0x102400 Read= 0x7c
Dato8 Addr= 0x102400 Read= 0x7c
Dato8 Addr= 0x102400 Read= 0x7c
Dato8 Addr= 0x102400 Read= 0x7c
Please help!
Regards,
- Angel Nino
I share the code.
SSI configure function
void ConfigureSSI(void) { MAP_SysCtlPeripheralReset (SYSCTL_PERIPH_GPIOA); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); MAP_GPIOPinConfigure(GPIO_PA2_SSI0CLK); //SCK MAP_GPIOPinConfigure(GPIO_PA3_SSI0FSS); //CS MAP_GPIOPinConfigure(GPIO_PA4_SSI0XDAT0); //Tx (MOSI) MAP_GPIOPinConfigure(GPIO_PA5_SSI0XDAT1); //RX (MISO) MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); MAP_SSIConfigSetExpClk(SSI0_BASE, 120000000, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 8000000, 8); MAP_SSIAdvModeSet(SSI0_BASE, SSI_ADV_MODE_READ_WRITE); MAP_SSIAdvFrameHoldEnable(SSI0_BASE); MAP_SSIEnable(SSI0_BASE); }
write and read functions
void ft800cmd_Write(unsigned char ftCommand) { // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_CS, 0); // Set chip select low // while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx)); SSIDataPut(SSI0_BASE, ftCommand); // Send command SSIDataPut(SSI0_BASE, 0x00); // Send first filler byte SSIAdvDataPutFrameEnd(SSI0_BASE, 0x00); // Send second filler byte // while(SSIBusy(SSI0_BASE)); // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_CS, GPIO_PIN_CS); // Set chip select high } unsigned char ft800mem_Read8(unsigned long ftAddress) { unsigned char ftData8 = 0; // Place-holder for 8-bits being read unsigned char cTempAddr[3]; // FT800 Memory Address unsigned char cZeroFill = ZERO; cTempAddr[2] = (char) (ftAddress >> 16) | MEM_READ; // Compose the command and address to send cTempAddr[1] = (char) (ftAddress >> 8); // middle byte cTempAddr[0] = (char) (ftAddress); // low byte // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_CS, 0); // Set chip select low // while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx)); SSIDataPut(SSI0_BASE, cTempAddr[2]); // Send Memory Write plus high address byte SSIDataPut(SSI0_BASE, cTempAddr[1]); SSIDataPut(SSI0_BASE, cTempAddr[0]); SSIAdvDataPutFrameEnd(SSI0_BASE, cZeroFill); // Send dummy byte SSIDataGet(SSI0_BASE, &ftData8); // Receive data byte // while(SSIBusy(SSI0_BASE)); // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_CS, GPIO_PIN_CS); // Set chip select high return ftData8; // Return 8-bits } unsigned int ft800mem_Read16(unsigned long ftAddress) { unsigned int ftData16 = 0; // 16-bits to return unsigned char cTempAddr[3]; // FT800 Memory Address unsigned char cTempData[2]; // Place-holder for 16-bits being read unsigned char cZeroFill = ZERO; cTempAddr[2] = (char) (ftAddress >> 16) | MEM_READ; // Compose the command and address to send cTempAddr[1] = (char) (ftAddress >> 8); // middle byte cTempAddr[0] = (char) (ftAddress); // low byte // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_CS, 0); // Set chip select low // while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx)); SSIDataPut(SSI0_BASE, cTempAddr[2]); // Send Memory Write plus high address byte SSIDataPut(SSI0_BASE, cTempAddr[1]); SSIDataPut(SSI0_BASE, cTempAddr[0]); SSIAdvDataPutFrameEnd(SSI0_BASE, cZeroFill); // Send dummy byte SSIDataGet(SSI0_BASE, &cTempData[0]); // Receive data byte SSIDataGet(SSI0_BASE, &cTempData[1]); // while(SSIBusy(SSI0_BASE)); // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_CS, GPIO_PIN_CS); // Set chip select high ftData16 = (cTempData[1]<< 8) | // Compose value to return - high byte (cTempData[0]); // low byte return ftData16; // Return 16-bits }
main function
int main(void) { int value; unsigned char ft800Gpio; MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); //enable pin for SW_1 and pull_up GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); //enable pin for SW_1 and pull_up SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); GPIOPinTypeGPIOInput(GPIO_PORTN_BASE, GPIO_PIN_INT); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_PD | GPIO_PIN_CS | GPIO_PIN_1 | GPIO_PIN_0); //enable pines for LED_2 and LED_1 ConfigureSSI(); ConfigureUART(); UARTprintf("*** SSI_0 & UART_0 done ***\n"); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_PD, GPIO_PIN_PD); // Initial state of PD_N - high GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_CS, GPIO_PIN_CS); // Initial state of SPI CS - high MAP_SysCtlDelay((120000000 * 0.02) / 3); // delay 20ms ft800cmd_Write(FT800_ACTIVE); // Start FT800 while(1) { if((GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0) & GPIO_PIN_0) == 0) { SysCtlDelay((120000000 * 0.15) / 3); if (value == 0) { unsigned char dato8 = ft800mem_Read8(REG_ID); // REG_GPIO, REG_GPIO_DIR, REG_ID, ROM_CHIPID UARTprintf("Dato8 Addr= 0x%x\tRead= 0x%x\n", REG_ID, dato8); value = 1; } } else if((GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_1) & GPIO_PIN_1) == 0) { SysCtlDelay((120000000 * 0.15) / 3); if (value == 0) { unsigned int dato16 = ft800mem_Read16(REG_PLAYBACK_FREQ); // REG_CMD_READ, REG_CMD_WRITE UARTprintf("Dato16 Addr= 0x%x\tRead= 0x%x\n", REG_PLAYBACK_FREQ, dato16); value = 1; } } else { value = 0; } } }