2018-06-05 11:09 PM
Hello,
i have a aplication where a SPI master from the stm32 chip is connected to 30 pieces of mux chips.
Each of the 30 spi channels has a enable signal connected to diferent gpio ports on the mcu side.
The enable signals are named EN1....EN30, but for example en1 is on GPIOA PA3, EN11 is on GPIOB PB7, en30 is on GPIOD PD9.
Is it posible to store these gpio ports and gpio pins like a array structure?
Something like:
port_array[30] = { GPIOA.......GPIOD }
port_pins[30] = { GPIO_Pin_3....
GPIO_Pin_9 }
for( i=0; i<30; i++) {
port_array[i] -> BSRRH = port_pins[i]; // set port Lo
between here i send the data over master spi
port_array[i] -> BSRRL = port_pins[i]; // set port Hi
}
2018-06-05 11:23 PM
Hello,
one option would be to create custom structure and then array of your pins:
typedef struct {
GPIO_TypeDef* gpio;
uint16_t pin;
} my_pin_t;
const my_pin_t
cs_pins[] = {
{ GPIOA, GPIO_PIN_0 },
{ GPIOB, GPIO_PIN_1 },
....,
}
#define E0 0
#define E1 1
...
//And call:
cs_pins[E0].port->BSRR = cs_pins[E0].pin�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?;
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
This is more standard C question.
Best regards,
Tilen
2018-06-06 03:12 AM
generally you can define a datatype that has a pointer to the port and a mask for the pin. and then form an array of such datatype.
like this:
typedef struct {
GPIO_TypeDef *port; //port
uint32_t mask; //32-bit pin mask
} PIN_TypeDef;
const PIN_TypeDef pin_array[]={
{GPIOB, 1<<2}, //PB2
{GPIOA, 1<<6}, //PA6
...
}
an example can be found here:
2018-06-06 03:19 AM
Another option would be a 4-bit multiplexer IC.
Thirty pins as chip select is quite a lot, you may find out later you need them for other purposes.