From 6301aad16983dca0ac34c285bbeee7944075ddde Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 11 Jun 2017 21:30:02 +0200 Subject: Test program working --- fw/main.c | 84 ++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 30 deletions(-) (limited to 'fw/main.c') diff --git a/fw/main.c b/fw/main.c index d29ef9e..6113a10 100644 --- a/fw/main.c +++ b/fw/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include /* @@ -14,12 +15,30 @@ void tick(void) { __asm__("nop"); } +void spi_send(int data) { + SPI1->DR = data; + while (SPI1->SR & SPI_SR_BSY); +} + +void strobe_aux(void) { + GPIOA->BSRR = GPIO_BSRR_BS_10; + tick(); + GPIOA->BSRR = GPIO_BSRR_BR_10; +} + +void strobe_leds(void) { + GPIOA->BSRR = GPIO_BSRR_BS_9; + tick(); + GPIOA->BSRR = GPIO_BSRR_BR_9; +} + int main(void) { RCC->CR |= RCC_CR_HSEON; while (!(RCC->CR&RCC_CR_HSERDY)); RCC->CFGR &= ~RCC_CFGR_PLLMUL_Msk & ~RCC_CFGR_SW_Msk; RCC->CFGR |= (2<CFGR2 &= ~RCC_CFGR2_PREDIV_Msk; /* PREDIV=0 */ + RCC->CFGR2 &= ~RCC_CFGR2_PREDIV_Msk; + RCC->CFGR2 |= RCC_CFGR2_PREDIV_DIV2; RCC->CR |= RCC_CR_PLLON; while (!(RCC->CR&RCC_CR_PLLRDY)); RCC->CFGR |= (2<MODER |= (2<OSPEEDR |= - (3<AFR[0] |= (0<CR1 = SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_SPE | (7<CR2 = (7<I2SCFGR = 0; + SPI1->CR2 &= ~SPI_CR2_DS_Msk; + SPI1->CR2 &= ~SPI_CR2_DS_Msk; + SPI1->CR2 |= LL_SPI_DATAWIDTH_16BIT; + /* FIXME maybe try w/o BIDI */ + SPI1->CR1 = SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_SPE | (1<BSRR = GPIO_BSRR_BR_6; while (42) { - for (int i=0; i<6; i++) { - if (pos1 == i) { - SPI1->DR = 1<DR = 0; - } - while (SPI1->SR & SPI_SR_BSY); - tick(); + if (i == 8) { + i = 0; + val = ~val; } - pos2 += 1; - if (pos2 == 8) { - pos2 = 0; - pos1 += 1; - if (pos1 == 6) - pos1 = 0; + spi_send((i&1 ? 0xfa00 : 0xf000) | (0xff^(1<BSRR = GPIO_BSRR_BS_9 | GPIO_BSRR_BS_10; - tick(); - GPIOA->BSRR = GPIO_BSRR_BR_9 | GPIO_BSRR_BR_10; - LL_mDelay(1); + i++; + spi_send((i&16) ? 0 : (1<