cancel
Showing results for 
Search instead for 
Did you mean: 

SPI communication between STM32F407VG board and Eval-STPM34 metrology board ?!!

Tristan LLoris
Associate

Hi,

I want to do SPI communication between STM32F407VG board and Eval-STPM34 metrology board , i am trying to read just a register of the Eval-STPM34 but i always fail , i used these pins to ensure the SPI communication :

STM32 -----> EVAL-STPM34

MOSI-----> MOSI

MISO-----> MISO

SCL -----> SCL

PC1 -----> SCS

PC2 -----> SYN

PC3 -----> EN

PA0 -----> LED2

GND -----> GND

VCC -----> VCC

And i made the CubeMX configuration below ....

I found in the datasheet and user manual of STPM34 that i have to initialize the STPM34 :

1-"If the SCS is set low and EN pin goes from low to high, the STPM32 communicates by SPI

mode. If the SCS is set high and EN pin goes from low to high, the STPM32 communicates

by UART mode. The STPM32 EN pin can be tied to VDD thanks to a pull-up if it is not

driven (EVALSTPM32 board). In this case, no additional wire between the STM32F103RD

and the STPM32 is needed.

EN pin can be also driven by FW:

- Put EN low to reset the configuration

- Set the desired level on SCS (for SPI or UART)

- Put EN high level to latch the configuration "

i want a SPI communication so i edited this code :

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); //Reset EN

DWT_Delay_us(1000);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_RESET); //Reset SCS

DWT_Delay_us(1000);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); //Set EN

2-i found also that i must initialize SYN

"As mentioned in the STPM34 datasheet, after the POR, the chip must be reset by toggling

3 times SYN pin and once SCS pin."

and you find the sequence of reset below ......

So i edited this code :

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_SET); //SET SCS

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_2,GPIO_PIN_SET); //SET SYN

  

 for(uint8_t i=0;i<=2; i++) 

 {

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_2,GPIO_PIN_RESET); //Reset SYN

DWT_Delay_us(100);

  HAL_GPIO_WritePin(GPIOC,GPIO_PIN_2,GPIO_PIN_SET); //Set SYN

DWT_Delay_us(100);

 }

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_RESET); //Reset SCS

DWT_Delay_us(100);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_SET); // SET SCS

3-And finally i want to read the register row 2 which it default value is 0x000004E0 , it address is 0x04 as mentionned in the datasheet of STPM34 so i edited this code :

spi_txbuff[0]=0x04; //buffer contains adress of the register

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_RESET); //RESET SCS

HAL_SPI_Transmit(&hspi1,spi_txbuff,1,50); //Send register adress

HAL_SPI_Receive(&hspi1,spi_rxbuff,4,50); //Read register data (4 bytes)

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_1,GPIO_PIN_SET); //SET SCS

And unfortunately in debugging mode i always find : 0xFF 0xFF 0xFF 0xFF

Wish your help,please!!

0 REPLIES 0