Skip to main content
SIDRI.1
Associate III
June 11, 2020
Question

Assigning SPI1 pins (STM32F103RBT6), to an external SPI device (ADS1220)

  • June 11, 2020
  • 2 replies
  • 899 views

Hi !

i'm trying to write a driver, to interface the "ADS1220" device with STM32F103RBT6, using SPI,

i would like to assign each pin of the MCU SPI (PA4, PA5, PA6, PA7) with its corresponding pin of ADS1220 like this : using macros

#define ADS_CS PA4 // or the adress of PA4 of MCU

#define ADS_CLK PA5 // or Address of PA5 of MCU

and so on...

i have received some suggestion about using structure pointer method

i have made a sketch as follow :

#include "stm32f10x.h" // Device header

typedef struct ADS_PIN{

uint32_t CS; // CS PIN of ADS1220 device

uint32_t CLK; // CLK PIN of ADS1220 device

uint32_t DOUT; // DOUT PIN of ADS1220 device

uint32_t DIN; // DIN PIN of ADS1220 device

} ADS_PIN;

ADS_PIN *pointer;

ADS_PIN.CS = GPIOA->BSRR|= (1<<4) // PA4 MCU

ADS_PIN.CLK = GPIOA->BSRR| = (1<<5) // PA5 MCU

ADS_PIN.DIN = GPIOA->BSRR| = (1<<6) // PA6 MCU

ADS_PIN.DOUT = GPIOA->BSRR| = (1<<7) // PA7 MCU

but, i'm confused, it may be sound silly , but i'm trying to understand how to specify that CS / CLK / DIN and DOUT pins correspond to PA / PA5 etc...;

if you could give me a suggestion

Thank you !

This topic has been closed for replies.

2 replies

Nikita91
Lead II
June 11, 2020

You don't need this kind of macros. The SPI peripheral manage itself all the SPI pins. The user must not interfere with these pins (except possibly with CS).

1) Physically connect the pins of the ADS to the SPI pins of the MCU,

2) Remap the SPI GPIO (PA4, PA5, ...) to SPI: If you use bare metal register programming set AFIO->MAPR to the proper value.

3) Configure and use the SPI to communicate with the ADS.

Your driver should write to the ADS or read from the ADS through the SPI peripheral, not the GPIO.

Please read the F1 reference manual.

SIDRI.1
SIDRI.1Author
Associate III
June 12, 2020

Thank you for your response,

i have just configured CS pin as GPIO, the other (SPI) pins as alternate function, of course i have read the datasheet CD00171190 ,

Best regards,