From 53794430bb76a0986d8c96ef81c3135217ee23dc Mon Sep 17 00:00:00 2001 From: Rutherther Date: Thu, 2 Jan 2025 21:38:09 +0100 Subject: [PATCH] fix(stm_spi_funduino): reception of spi numbers --- stm_spi_funduino/.dir-locals.el | 4 ++-- stm_spi_funduino/Makefile | 2 +- stm_spi_funduino/src/display.c | 4 ++-- stm_spi_funduino/src/main.c | 42 +++++---------------------------- 4 files changed, 11 insertions(+), 41 deletions(-) diff --git a/stm_spi_funduino/.dir-locals.el b/stm_spi_funduino/.dir-locals.el index e9102ab..76a6737 100644 --- a/stm_spi_funduino/.dir-locals.el +++ b/stm_spi_funduino/.dir-locals.el @@ -21,7 +21,7 @@ modes (c-mode c-ts-mode c++-mode c++-ts-mode) command-cwd dape-command-cwd command "arm-none-eabi-gdb" command-args - ("--interpreter=dap" "--x=gdb.script" "bin/mam-arm04.elf") - defer-launch-attach t :request "launch" :program "bin/mam-arm04.elf" :args + ("--interpreter=dap" "--x=gdb.script" "bin/spi-num-receiver.elf") + defer-launch-attach t :request "launch" :program "bin/spi-num-receiver.elf" :args [] :stopAtBeginningOfMainSubprogram nil)))))) diff --git a/stm_spi_funduino/Makefile b/stm_spi_funduino/Makefile index 332733f..e856858 100644 --- a/stm_spi_funduino/Makefile +++ b/stm_spi_funduino/Makefile @@ -2,7 +2,7 @@ DEVICE?=STM32F401xE TARGET?=stm32f4x CPU?=cortex-m7 -APP=mam-arm04.elf +APP=spi-num-receiver.elf BINDIR=bin SRCDIR=src diff --git a/stm_spi_funduino/src/display.c b/stm_spi_funduino/src/display.c index 09ed8aa..19bf7d7 100644 --- a/stm_spi_funduino/src/display.c +++ b/stm_spi_funduino/src/display.c @@ -85,8 +85,8 @@ void display_dots(display_t* display, uint8_t dots) { void display_convert_number(display_t *display, uint32_t number) { uint32_t digit = 0; for (uint8_t i = 0; i < display->digits_count; i++) { - digit = (number % 10) << (i << 2); - display->digits[i] = digit; + digit = (number % 10); + display->digits[display->digits_count - 1 - i] = digit + '0'; number /= 10; } } diff --git a/stm_spi_funduino/src/main.c b/stm_spi_funduino/src/main.c index b21aa4e..75a6312 100644 --- a/stm_spi_funduino/src/main.c +++ b/stm_spi_funduino/src/main.c @@ -92,7 +92,7 @@ void main() RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN; RCC->APB1ENR |= RCC_APB1ENR_TIM3EN | RCC_APB1ENR_USART2EN; - RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; + RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN | RCC_APB2LPENR_SPI1LPEN; // The timer clocks are at 12 MHz. // For 100 Hz, the prescaler would be 120 000. That is too big, @@ -153,8 +153,8 @@ void main() pin_into_alternate(&pin_csn, 5); spi_init(&spi, pin_csn, SPI1, 1); - spi_slave_configure(&spi, false, false, false, SPI_MSB_FIRST, SPI_FRAME_8_BIT); - spi_enable_interrupt(&spi, false, true); + spi_slave_configure(&spi, false, false, false, SPI_MSB_FIRST, SPI_FRAME_16_BIT); + /* spi_enable_interrupt(&spi, false, true); */ spi_slave_enable(&spi, true); } @@ -165,9 +165,7 @@ void main() timer_enable(&display_timer); __enable_irq(); - - char buffer[64]; - uint16_t idx = 0; + display_convert_number(&display, 9999); // Application while (1) { @@ -176,37 +174,9 @@ void main() continue; } - buffer[idx] = (char)rx; - usart_transmit(&uart, &buffer[idx], 1); - - if (buffer[idx] != '\n') { - idx++; - continue; - } - - buffer[idx] = '\0'; - idx = 0; - - converted_number_t converted = convert_number(buffer); - - if (converted.error) { - display_digits_set(&display, "Err\0"); - display_dots(&display, 0); - } else { - uint8_t empty_count = DIGITS - converted.digits_count; - display_dots(&display, converted.dot << empty_count); - for (uint8_t digit = 0; digit < DIGITS; digit++) { - char value = '\0'; - - if (digit >= empty_count) { - value = converted.digits[digit - empty_count]; - } - - display_digit_set(&display, digit, value); - } - - } + /* usart_transmit(&uart, &buffer[idx], 1); */ + display_convert_number(&display, rx); /* DELAY_US(100); */ } } -- 2.48.1