Last active
July 19, 2017 12:23
-
-
Save ChuckM/df360ba3df235f482561 to your computer and use it in GitHub Desktop.
SPI Test that Doesn't work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* makes capturing the output with a logic analyzer easier */ | |
#define FLAG_ON gpio_set(GPIOC, GPIO2) | |
#define FLAG_OFF gpio_clear(GPIOC, GPIO2) | |
/* | |
* This then sets up the SPI2 port | |
*/ | |
void | |
spi_test(void) { | |
rcc_periph_clock_enable(RCC_SPI1); | |
/* Move the GPIO B bits over Alternate Function 5 -- SPI #1 */ | |
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO3 | GPIO4 | GPIO5); | |
gpio_set_af(GPIOB, GPIO_AF5, GPIO3 | GPIO4 | GPIO5); | |
/* Initialize us as a MASTER, Mode 0, FPCLK/16, SPI port */ | |
spi_init_master(SPI1, SPI_CR1_BAUDRATE_FPCLK_DIV_16, | |
SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE, | |
SPI_CR1_CPHA_CLK_TRANSITION_1, | |
SPI_CR1_DFF_8BIT, | |
SPI_CR1_MSBFIRST); | |
/* Enable SPI */ | |
spi_enable(SPI1); | |
/* Run the test, end out four bytes */ | |
FLAG_ON; | |
spi_send(SPI1, 0x55); | |
spi_send(SPI1, 0xAA); | |
spi_send(SPI1, 0x0); | |
spi_send(SPI1, 0xff); | |
FLAG_OFF; | |
while(1) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment