Skip to content

Instantly share code, notes, and snippets.

@MightyPork
Created May 21, 2016 21:54
Show Gist options
  • Select an option

  • Save MightyPork/37263d91947020e0010f3cd6de9b79db to your computer and use it in GitHub Desktop.

Select an option

Save MightyPork/37263d91947020e0010f3cd6de9b79db to your computer and use it in GitHub Desktop.
/**
* @brief Configure SPI
*/
static void conf_spi(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2ENR_SPI1EN, ENABLE);
SPI_InitTypeDef spi_cnf;
SPI_StructInit(&spi_cnf);
spi_cnf.SPI_Direction = SPI_Direction_1Line_Tx;
spi_cnf.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI1, &spi_cnf);
SPI_Cmd(SPI1, ENABLE);
}
/**
* @brief Configure GPIOs
*/
static void conf_gpio(void)
{
GPIO_InitTypeDef gpio_cnf;
GPIO_StructInit(&gpio_cnf);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// SPI
gpio_cnf.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;
gpio_cnf.GPIO_Mode = GPIO_Mode_AF_PP;
gpio_cnf.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOA, &gpio_cnf);
}
int main(void)
{
// init...
while (1) {
dbg("Send byte!");
SPI1->DR = 0xA5;
dbg("Waiting");
while (!(SPI1->SR & SPI_SR_TXE));
dbg("Sent."); // NEVER
delay_ms(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment