diff --git a/src/drivers/si4063/si4063.c b/src/drivers/si4063/si4063.c index b4f5258..7a57bc5 100644 --- a/src/drivers/si4063/si4063.c +++ b/src/drivers/si4063/si4063.c @@ -100,7 +100,7 @@ static void si4063_send_command(uint8_t command, uint8_t length, uint8_t *data) si4063_set_chip_select(true); // Output enable time, 20ns - for (uint32_t i = 0; i < 0xFFFF; i++); + for (uint32_t i = 0; i < 0xFFFFF; i++); spi_send(command); @@ -114,8 +114,8 @@ static void si4063_send_command(uint8_t command, uint8_t length, uint8_t *data) static void si4063_power_up() { uint8_t data[] = { - 0x01, // - 0x01, // No patch, boot main app. img, TXCO + 0x01, // 0x01 = FUNC PRO - Power the chip up into EZRadio PRO functional mode. + 0x01, // 0x01 = Reference signal is derived from an external TCXO. (SI4063_CLOCK >> 24) & 0xFF, // VCXO frequency (SI4063_CLOCK >> 16) & 0xFF, (SI4063_CLOCK >> 8) & 0xFF, @@ -313,7 +313,7 @@ int32_t si4063_read_temperature_celsius_100() si4063_read_response(sizeof(response), response); for (int i = 0; i < sizeof(response); i++) { - log_info("response: %02x\n", response[i]); + log_info("Si4063 ADC reading: %02x\n", response[i]); } // Calculate the temperature in C * 10 @@ -336,7 +336,7 @@ uint8_t si4063_read_part_info() si4063_read_response(sizeof(response), response); for (int i = 0; i < sizeof(response); i++) { - log_info("part info: %02x\n", response[i]); + log_info("Si4063 part info: %02x\n", response[i]); } return response[0]; @@ -393,6 +393,7 @@ void si4063_init() si4603_set_shutdown(true); delay_us(20); si4603_set_shutdown(false); + delay_us(50); si4063_power_up(); diff --git a/src/hal/spi.c b/src/hal/spi.c index 5a457bd..9a3aea6 100644 --- a/src/hal/spi.c +++ b/src/hal/spi.c @@ -23,7 +23,12 @@ void spi_init() // MISO gpio_init.GPIO_Pin = PIN_MISO; +#ifdef RS41 gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING; +#endif +#ifdef DFM17 + gpio_init.GPIO_Mode = GPIO_Mode_IPU; +#endif gpio_init.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(BANK_MISO, &gpio_init); @@ -46,7 +51,8 @@ void spi_init() spi_init.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; #endif #ifdef DFM17 - spi_init.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; + // TODO: Adjust SPI speed correctly, not sure what this should be + spi_init.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; #endif spi_init.SPI_FirstBit = SPI_FirstBit_MSB; #ifdef RS41 @@ -58,10 +64,18 @@ void spi_init() #endif SPI_Init(PERIPHERAL_SPI, &spi_init); +#ifdef RS41 SPI_SSOutputCmd(PERIPHERAL_SPI, ENABLE); +#endif +#ifdef DFM17 + SPI_CalculateCRC(PERIPHERAL_SPI, DISABLE); +#endif SPI_Cmd(PERIPHERAL_SPI, ENABLE); +#ifdef RS41 + // TODO: Why is this call even here? SPI_Init(PERIPHERAL_SPI, &spi_init); +#endif } void spi_uninit() @@ -84,24 +98,36 @@ void spi_uninit() GPIO_Init(BANK_MOSI, &gpio_init); } -inline void spi_send(uint16_t data) +void spi_send(uint16_t data) { // Wait for TX buffer while (SPI_I2S_GetFlagStatus(PERIPHERAL_SPI, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(PERIPHERAL_SPI, data); +#ifdef DFM17 + while (SPI_I2S_GetFlagStatus(PERIPHERAL_SPI, SPI_I2S_FLAG_TXE) == RESET); + while (SPI_I2S_GetFlagStatus(PERIPHERAL_SPI, SPI_I2S_FLAG_BSY) == SET); +#endif } -inline uint8_t spi_receive() +uint8_t spi_receive() { // Wait for data in RX buffer +#ifdef DFM17 + while (SPI_I2S_GetFlagStatus(PERIPHERAL_SPI, SPI_I2S_FLAG_BSY) == SET); +#endif while (SPI_I2S_GetFlagStatus(PERIPHERAL_SPI, SPI_I2S_FLAG_RXNE) == RESET); return (uint8_t) SPI_I2S_ReceiveData(PERIPHERAL_SPI); } -inline uint8_t spi_read() +uint8_t spi_read() { - spi_send(0xFF); - return spi_receive(); + // TODO: This is the minimal read routine, not sure if reading the other registers has an effect? + while (SPI_I2S_GetFlagStatus(PERIPHERAL_SPI, SPI_I2S_FLAG_BSY) == SET); + SPI_I2S_SendData(PERIPHERAL_SPI, 0xFF); + while (SPI_I2S_GetFlagStatus(PERIPHERAL_SPI, SPI_I2S_FLAG_RXNE) == RESET); + return (uint8_t) SPI_I2S_ReceiveData(PERIPHERAL_SPI); + /*spi_send(0xFF); + return spi_receive();*/ } void spi_set_chip_select(GPIO_TypeDef *gpio_cs, uint16_t pin_cs, bool select) diff --git a/src/hal/system.c b/src/hal/system.c index 5192020..02d9e01 100644 --- a/src/hal/system.c +++ b/src/hal/system.c @@ -305,20 +305,38 @@ void system_enable_tick() void system_set_green_led(bool enabled) { +#ifdef RS41 if (enabled) { GPIO_ResetBits(BANK_GREEN_LED, PIN_GREEN_LED); } else { GPIO_SetBits(BANK_GREEN_LED, PIN_GREEN_LED); } +#endif +#ifdef DFM17 + if (enabled) { + GPIO_SetBits(BANK_GREEN_LED, PIN_GREEN_LED); + } else { + GPIO_ResetBits(BANK_GREEN_LED, PIN_GREEN_LED); + } +#endif } void system_set_red_led(bool enabled) { +#ifdef RS41 if (enabled) { GPIO_ResetBits(BANK_RED_LED, PIN_RED_LED); } else { GPIO_SetBits(BANK_RED_LED, PIN_RED_LED); } +#endif +#ifdef DFM17 + if (enabled) { + GPIO_SetBits(BANK_RED_LED, PIN_RED_LED); + } else { + GPIO_ResetBits(BANK_RED_LED, PIN_RED_LED); + } +#endif } void system_disable_irq()