I 'm facing some trouble with a SPI connected LCD. The LCD is connected to SPI3, but could not measure a clock pulse on the SPI SCK (GPIOB 3) line.
Anyway, I suspected an user error, and decided to try one of the SPI samples (\testhal\STM32F4xx\SPI).
This is by default configured for SPI2, and when I run this, I can measure the SPI SCK (GPIOB 13) just fine.
However, when I make the needed changes to use SPI3 instead of SPI2, I can't measure a clock (GPIOB 3).
Anybody an idea why this could be?
STM32_SPI_USE_SPI3 TRUE is set in mcuconf.h, but otherwise I would have compilers errors anyway.
Thanks in advance!
Code: Select all
#include "ch.h"
#include "hal.h"
/*
* Maximum speed SPI configuration (21MHz, CPHA=0, CPOL=0, MSb first).
*/
static const SPIConfig hs_spicfg = {
NULL,
GPIOC,
2,
0
};
/*
* Low speed SPI configuration (328.125kHz, CPHA=0, CPOL=0, MSb first).
*/
static const SPIConfig ls_spicfg = {
NULL,
GPIOC,
2,
SPI_CR1_BR_2 | SPI_CR1_BR_1
};
/*
* SPI TX and RX buffers.
*/
static uint8_t txbuf[512];
static uint8_t rxbuf[512];
/*
* SPI bus contender 1.
*/
static WORKING_AREA(spi_thread_1_wa, 256);
static msg_t spi_thread_1(void *p) {
(void)p;
chRegSetThreadName("SPI thread 1");
while (TRUE) {
spiAcquireBus(&SPID3); /* Acquire ownership of the bus. */
palSetPad(GPIOD, GPIOD_LED5); /* LED ON. */
spiStart(&SPID3, &hs_spicfg); /* Setup transfer parameters. */
spiSelect(&SPID3); /* Slave Select assertion. */
spiExchange(&SPID3, 512, txbuf, rxbuf); /* Atomic transfer operations. */
spiUnselect(&SPID3); /* Slave Select de-assertion. */
spiReleaseBus(&SPID3); /* Ownership release. */
}
return 0;
}
/*
* SPI bus contender 2.
*/
static WORKING_AREA(spi_thread_2_wa, 256);
static msg_t spi_thread_2(void *p) {
(void)p;
chRegSetThreadName("SPI thread 2");
while (TRUE) {
spiAcquireBus(&SPID3); /* Acquire ownership of the bus. */
palClearPad(GPIOD, GPIOD_LED5); /* LED OFF. */
spiStart(&SPID3, &ls_spicfg); /* Setup transfer parameters. */
spiSelect(&SPID3); /* Slave Select assertion. */
spiExchange(&SPID3, 512, txbuf, rxbuf); /* Atomic transfer operations. */
spiUnselect(&SPID3); /* Slave Select de-assertion. */
spiReleaseBus(&SPID3); /* Ownership release. */
}
return 0;
}
/*
* Application entry point.
*/
int main(void) {
unsigned i;
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
/*
* SPI2 I/O pins setup.
*/
palSetPadMode(GPIOB, 3, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* New SCK. */
palSetPadMode(GPIOB, 4, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* New MISO. */
palSetPadMode(GPIOB, 5, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* New MOSI. */
palSetPadMode(GPIOC, 2, PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST); /* New CS. */
palSetPad(GPIOC, 2);
/*
* Prepare transmit pattern.
*/
for (i = 0; i < sizeof(txbuf); i++)
txbuf[i] = (uint8_t)i;
/*
* Starting the transmitter and receiver threads.
*/
chThdCreateStatic(spi_thread_1_wa, sizeof(spi_thread_1_wa),
NORMALPRIO + 1, spi_thread_1, NULL);
chThdCreateStatic(spi_thread_2_wa, sizeof(spi_thread_2_wa),
NORMALPRIO + 1, spi_thread_2, NULL);
/*
* Normal main() thread activity, in this demo it does nothing.
*/
while (TRUE) {
chThdSleepMilliseconds(500);
}
return 0;
}