cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Mode for non standard sampling edges

Jorge Calatayud Maeso
Associate II

Hi, i am currently working on a driver for a Chineese IC. The manufacturer recomends implementing SPI protocol over an FPGA, but for cost reasons we would like to use a MCU.

The SPI protocol that the chip uses has the following configuration

"Chip SPI samples SDI on the ris ing edge of SCL K and the rising edge of SCLK

outputs SDO, so the external host needs to output SDI on the falling edge of SCLK and sample SDO on the falling edge of SCLK."

We've been able to comunicate with the chip with some success, but due to sampling instant we are reading the correct output but 1 bit to the left.

Is there any way to configure this sampling description besides changing CPOL CPHAS configuration in the middle of the SPI transaction?

This is our reading function right now:

HAL_SPICLK_TO_GPIO(chip);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

HAL_GPIO_TO_SPICLK(chip);

//SPI Read Command

HAL_GPIO_WritePin(chip->cs.bench, chip->cs.pin, GPIO_PIN_RESET);

ret = HAL_SPI_Transmit(chip->hspi, data,3, XPHASED_SPI_TIMEOUT);

HAL_GPIO_WritePin(chip->cs.bench, chip->cs.pin, GPIO_PIN_SET);

if(ret != HAL_OK){

return 1;

}

//Additional Clock Cycles

HAL_SPICLK_TO_GPIO(chip);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

HAL_GPIO_TO_SPICLK(chip);

//uint8_t z = 0x00;

//ret = HAL_SPI_Transmit(chip->hspi,&z,3, 1000);

//SPI Reading Operation

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);

ret = HAL_SPI_TransmitReceive(chip->hspi,data,rx,1, 1000);

HAL_SPI_change_clk_phase(chip, SPI_PHASE_1EDGE,SPI_POLARITY_HIGH);

ret = HAL_SPI_Receive(chip->hspi,rx+1,1, 1000);

ret = HAL_SPI_Receive(chip->hspi,rx+2,1, 1000);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);

if(ret != HAL_OK){

return 1;

}

HAL_SPI_change_clk_phase(chip, SPI_PHASE_1EDGE, SPI_POLARITY_LOW);

HAL_SPICLK_TO_GPIO(chip);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

HAL_GPIO_TO_SPICLK(chip);

1 REPLY 1
TDK
Guru

No way to do that with a single SPI, but you could use two SPIs to achieve the same thing. One as receive only slave, the other as a transmit only slave.

If you feel a post has answered your question, please click "Accept as Solution".