~ruther/vhdl-spi-2

53794430bb76a0986d8c96ef81c3135217ee23dc — Rutherther 2 months ago abfea28
fix(stm_spi_funduino): reception of spi numbers
M stm_spi_funduino/.dir-locals.el => stm_spi_funduino/.dir-locals.el +2 -2
@@ 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))))))

M stm_spi_funduino/Makefile => stm_spi_funduino/Makefile +1 -1
@@ 2,7 2,7 @@ DEVICE?=STM32F401xE
TARGET?=stm32f4x
CPU?=cortex-m7

APP=mam-arm04.elf
APP=spi-num-receiver.elf

BINDIR=bin
SRCDIR=src

M stm_spi_funduino/src/display.c => stm_spi_funduino/src/display.c +2 -2
@@ 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;
  }
}

M stm_spi_funduino/src/main.c => stm_spi_funduino/src/main.c +6 -36
@@ 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); */
  }
}

Do not follow this link