Hi,
Im trying to use SPI2 of stm32f407 (discovery board)
But I can only see SCK and CSN activity, MOSI does not seem to output anything.. (trying to do a read) ?
Am I missing some configuration ?
this is what Ive got in my board.h:
198 #define VAL_GPIOB_MODER (PIN_MODE_INPUT(0) | \
199 PIN_MODE_INPUT(1) | \
200 PIN_MODE_INPUT(2) | \
201 PIN_MODE_INPUT(3) | \
202 PIN_MODE_INPUT(4) | \
203 PIN_MODE_INPUT(5) | \
204 PIN_MODE_INPUT(9) | \
205 PIN_MODE_INPUT(7) | \
206 PIN_MODE_OUTPUT(8) | \
207 PIN_MODE_ALTERNATE(9) | \
208 PIN_MODE_INPUT(10) | \
209 PIN_MODE_INPUT(11) | \
210 PIN_MODE_OUTPUT(12) | \
211 PIN_MODE_ALTERNATE(13) | \
212 PIN_MODE_ALTERNATE(14) | \
213 PIN_MODE_ALTERNATE(15))
214 #define VAL_GPIOB_OTYPER 0x00000000
215 #define VAL_GPIOB_OSPEEDR 0xFFFFFFFF
216 #define VAL_GPIOB_PUPDR (PIN_PUDR_PULLUP(0) | \
217 PIN_PUDR_PULLUP(1) | \
218 PIN_PUDR_PULLUP(2) | \
219 PIN_PUDR_PULLUP(3) | \
220 PIN_PUDR_PULLUP(4) | \
221 PIN_PUDR_PULLUP(5) | \
222 PIN_PUDR_PULLUP(6) | \
223 PIN_PUDR_PULLUP(7) | \
224 PIN_PUDR_PULLUP(8) | \
225 PIN_PUDR_PULLUP(9) | \
226 PIN_PUDR_PULLUP(10) | \
227 PIN_PUDR_PULLUP(11) | \
228 PIN_PUDR_PULLUP(12) | \
229 PIN_PUDR_FLOATING(13) | \
230 PIN_PUDR_FLOATING(14) | \
231 PIN_PUDR_FLOATING(15))
232 #define VAL_GPIOB_ODR 0xFFFFFFFF
233 #define VAL_GPIOB_AFRL 0x00000000
234 #define VAL_GPIOB_AFRH ( \
235 PIN_AFIO_AF(9, 5) | \
236 PIN_AFIO_AF(13, 5) | \
237 PIN_AFIO_AF(14, 5) | \
238 PIN_AFIO_AF(15, 5) \
239 )
240
And in my setup I do :
static const SPIConfig conf = {
.end_cb=NULL,
.ssport=GPIOB,
.sspad=9,
.cr1= SPI_CR1_BR_1| SPI_CR1_BR_2
};
spiStart(&SPI2, &conf);
palSetPad(GPIOB, 9);
palSetPadMode(GPIOB, 9, PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST); /* NSS. */
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* SCK. */
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5)); /* MISO. */
palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* MOSI. */
Thanks.
Spi question, stm32f4
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Spi question, stm32f4
Hi,
It looks OK, you don't need to change the board.h file if you reconfigure the pins using palSetPadMode().
There is a SPI test application under ./testhal/STM32F4xx/SPI that does exactly what you do, could you try that one and verify the output?
Giovanni
It looks OK, you don't need to change the board.h file if you reconfigure the pins using palSetPadMode().
There is a SPI test application under ./testhal/STM32F4xx/SPI that does exactly what you do, could you try that one and verify the output?
Giovanni
Re: Spi question, stm32f4
the demo does not seem to work.
looking at mosi. all i see is a square wave. instead of bits.
is there something with these pins to keep in mind, they seem to be shared with i2s. do i need to unconfigure
i2s if using spi?
looking at mosi. all i see is a square wave. instead of bits.
is there something with these pins to keep in mind, they seem to be shared with i2s. do i need to unconfigure
i2s if using spi?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Spi question, stm32f4
Hi,
Probably it is a measurement problem, in that demo you can connect MISO and MOSI together and data are read back exactly as transmitted. You don't need to reconfigure anything, it has to work as-is.
Giovanni
Probably it is a measurement problem, in that demo you can connect MISO and MOSI together and data are read back exactly as transmitted. You don't need to reconfigure anything, it has to work as-is.
Giovanni