MarlinFirmware / U8glib-HAL

Customized U8glib for use in Marlin 2.0
Other
45 stars 33 forks source link

Incorrect parameter to SPISettings in u8g_com_stm32duino_hw_spi.cpp #14

Closed ktand closed 5 years ago

ktand commented 5 years ago

In the u8g_com_stm32duino_hw_spi_fn() function in u8g_com_stm32duino_hw_spi.cpp the SPISettings is initialized with SPI_CLOCK_DIV2 instead of a clock speed:

    case U8G_COM_MSG_INIT:
      u8g_SetPIOutput(u8g, U8G_PI_CS);
      u8g_SetPIOutput(u8g, U8G_PI_A0);
      u8g_SetPIOutput(u8g, U8G_PI_RESET);

      u8g_SetPILevel(u8g, U8G_PI_CS, 1);

      spiConfig = SPISettings(SPI_CLOCK_DIV2, MSBFIRST, SPI_MODE0);
      SPI.begin();
      break;

SPI_CLOCK_DIV2 is defined as:

// Compatibility with sketches designed for AVR @ 16 MHz could not
// be ensured as SPI frequency depends of system clock configuration.
// user have to use appropriate divider for the SPI clock
// This function should not be used in new project.
// Use SPISettings with SPI.beginTransaction() to configure SPI parameters.
#define SPI_CLOCK_DIV2   2
#define SPI_CLOCK_DIV4   4
#define SPI_CLOCK_DIV8   8
#define SPI_CLOCK_DIV16  16
#define SPI_CLOCK_DIV32  32
#define SPI_CLOCK_DIV64  64
#define SPI_CLOCK_DIV128 128

in the core. The SPI_CLOCK_x constant was intended to be used with the obsolete SPI.setClockDivider(divider) function.

I'm not 100% sure but I think the SPISettings should be initialized with a speed of 2500000 (works fine with the FYSETC MINI 12864).

thinkyhead commented 5 years ago

I'll try 2.5 Mbits/s which is plenty fast, and maybe later we'll base it on the CPU speed. SPI can apparently go to 10 Mbits/s and higher.