revert mission timer to 32 bit, add signal level monitoring

This commit is contained in:
2025-05-05 09:02:48 +02:00
parent ee54abb663
commit 22d9f1f32a
10 changed files with 85 additions and 70 deletions

View File

@@ -1,6 +1,6 @@
{ {
"C_Cpp.intelliSenseEngine": "default", "C_Cpp.intelliSenseEngine": "default",
"idf.espIdfPath": "/home/bruno/esp/master/esp-idf", "idf.espIdfPath": "/home/bruno/esp/v5.4.1/esp-idf",
"idf.pythonInstallPath": "/usr/bin/python", "idf.pythonInstallPath": "/usr/bin/python",
"idf.openOcdConfigs": [ "idf.openOcdConfigs": [
"board/esp32s3-builtin.cfg" "board/esp32s3-builtin.cfg"

View File

@@ -2,7 +2,7 @@ dependencies:
idf: idf:
source: source:
type: idf type: idf
version: 5.5.0 version: 5.4.1
k0i05/esp_bme680: k0i05/esp_bme680:
component_hash: 2df0cb14d4425565a8745d4a96bfaa8ff7e90bbec3e208a073821406dded23c8 component_hash: 2df0cb14d4425565a8745d4a96bfaa8ff7e90bbec3e208a073821406dded23c8
dependencies: dependencies:

View File

@@ -18,7 +18,7 @@ typedef struct __attribute__((packed))
char syncPhrase[10]; //10 char syncPhrase[10]; //10
uint32_t packetIndex; //14 uint32_t packetIndex; //14
uint8_t packetType; //15 uint8_t packetType; //15
uint64_t missionTimer; //19 uint32_t missionTimer; //19
uint32_t CRCCheck; uint32_t CRCCheck;
} DownBoundPacket; } DownBoundPacket;

View File

@@ -202,6 +202,7 @@ void prepare_and_send_telemetry(uint64_t missionTimer)
fsync(fileno(csvFile)); // Critical: this ensures actual write to disk fsync(fileno(csvFile)); // Critical: this ensures actual write to disk
} }
printf("Sending %d byte packet hehe\n", offset);
send_packet_without_retries(bufOut, offset); send_packet_without_retries(bufOut, offset);
packetReadiness = 0; packetReadiness = 0;
} }

View File

@@ -26,11 +26,11 @@ void gps_init()
.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS, .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
.rx_flow_ctrl_thresh = 122, .rx_flow_ctrl_thresh = 122,
}; };
ESP_ERROR_CHECK(uart_param_config(GPS_UART_NUM, &uart_config)); ESP_ERROR_CHECK_WITHOUT_ABORT(uart_param_config(GPS_UART_NUM, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(GPS_UART_NUM, GPS_TXD, GPS_RXD, GPS_RTS, GPS_CTS)); ESP_ERROR_CHECK_WITHOUT_ABORT(uart_set_pin(GPS_UART_NUM, GPS_TXD, GPS_RXD, GPS_RTS, GPS_CTS));
const int uart_buffer_size = (1024 * 2); const int uart_buffer_size = (1024 * 2);
ESP_ERROR_CHECK(uart_driver_install(GPS_UART_NUM, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0)); ESP_ERROR_CHECK_WITHOUT_ABORT(uart_driver_install(GPS_UART_NUM, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
} }
@@ -51,7 +51,7 @@ void gps_task(void *arg)
if (line[0] == '$') { if (line[0] == '$') {
ESP_LOGI(TAG, "Received NMEA: %s", line); ESP_LOGI(TAG, "Received NMEA: %s", line);
if (strstr(line, "$GPGGA") == line) { if (strstr(line, "$GNGGA") == line) {
parse_gpgga(line); parse_gpgga(line);
parse_gpgga_to_struct(line, &gpsDataOut); parse_gpgga_to_struct(line, &gpsDataOut);
} else if (strstr(line, "$GPRMC") == line) { } else if (strstr(line, "$GPRMC") == line) {

View File

@@ -8,21 +8,26 @@ i2c_device_config_t INA260_DEV_CFG = {
i2c_master_dev_handle_t INA260_DEV_HANDLE; i2c_master_dev_handle_t INA260_DEV_HANDLE;
void ina260_reset()
void ina260_reset() { {
i2c_write_register_16(INA260_DEV_HANDLE, 0x00, 0x0FFF); // set ina max averaging and max time i2c_write_register_16(INA260_DEV_HANDLE, 0x00, 0x0FFF); // set ina max averaging and max time
} }
esp_err_t ina260_init() esp_err_t ina260_init()
{ {
esp_err_t ret = i2c_master_bus_add_device(i2c0_bus_hdl, &INA260_DEV_CFG, &INA260_DEV_HANDLE); esp_err_t ret = i2c_master_bus_add_device(i2c0_bus_hdl, &INA260_DEV_CFG, &INA260_DEV_HANDLE);
if (ret != ESP_OK) {return ret;} if (ret != ESP_OK)
{
ESP_LOGE(TAG_INA, "%s", esp_err_to_name(ret));
return ret;
}
ESP_LOGI(TAG_INA, "hehedstesfsewscdsfsrgerpodsvhdrsivhriuvjdreiv");
return i2c_write_register_16(INA260_DEV_HANDLE, INA260_CONFIG_REGISTER, return i2c_write_register_16(INA260_DEV_HANDLE, INA260_CONFIG_REGISTER,
CONFIG_AVG_1024 | CONFIG_VBUSCT_8_244MS | CONFIG_ISHCT_8_244MS | CONFIG_MODE_CURRENT_VOLTAGE_CONTINOUS); // set ina max averaging and max time CONFIG_AVG_1024 | CONFIG_VBUSCT_8_244MS | CONFIG_ISHCT_8_244MS | CONFIG_MODE_CURRENT_VOLTAGE_CONTINOUS); // set ina max averaging and max time
} }
esp_err_t i2c_master_read_register_transmit_receive(i2c_master_dev_handle_t device_handle, uint8_t reg_addr, uint8_t *data, size_t data_len)
esp_err_t i2c_master_read_register_transmit_receive(i2c_master_dev_handle_t device_handle, uint8_t reg_addr, uint8_t *data, size_t data_len) { {
esp_err_t ret; esp_err_t ret;
// The register address is what we want to send first (the "transmit" part) // The register address is what we want to send first (the "transmit" part)
@@ -39,7 +44,8 @@ esp_err_t i2c_master_read_register_transmit_receive(i2c_master_dev_handle_t devi
read_buffer, read_size, read_buffer, read_size,
I2C_TIMEOUT_MS_VALUE); I2C_TIMEOUT_MS_VALUE);
if (ret == ESP_OK) { if (ret == ESP_OK)
{
// Copy the data from the temporary read buffer to the output buffer // Copy the data from the temporary read buffer to the output buffer
memcpy(data, read_buffer, read_size); memcpy(data, read_buffer, read_size);
} }
@@ -49,6 +55,8 @@ esp_err_t i2c_master_read_register_transmit_receive(i2c_master_dev_handle_t devi
void ina260_readParams(uint16_t *volt, uint16_t *cur, uint16_t *pow) void ina260_readParams(uint16_t *volt, uint16_t *cur, uint16_t *pow)
{ {
if (INA260_DEV_HANDLE)
{
*volt = 0; *volt = 0;
*cur = 0; *cur = 0;
*pow = 0; *pow = 0;
@@ -56,7 +64,7 @@ void ina260_readParams(uint16_t *volt, uint16_t *cur, uint16_t *pow)
{ {
uint8_t reg_value[2] = {0}; // Buffer for storing register data uint8_t reg_value[2] = {0}; // Buffer for storing register data
ESP_ERROR_CHECK(i2c_master_read_register_transmit_receive(INA260_DEV_HANDLE, reg_addr, reg_value, sizeof(reg_value))); ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_read_register_transmit_receive(INA260_DEV_HANDLE, reg_addr, reg_value, sizeof(reg_value)));
// Perform the register read // Perform the register read
switch (reg_addr) switch (reg_addr)
{ {
@@ -74,6 +82,7 @@ void ina260_readParams(uint16_t *volt, uint16_t *cur, uint16_t *pow)
break; break;
} }
} }
}
} }
void ina260_printParams(uint16_t volt, uint16_t cur, uint16_t pow) void ina260_printParams(uint16_t volt, uint16_t cur, uint16_t pow)

View File

@@ -16,6 +16,7 @@ uint8_t gpiob_state = 0x00; // All LOW initially
esp_err_t mcp23018_set_pin(i2c_master_dev_handle_t dev_handle, uint8_t pin, uint8_t value) esp_err_t mcp23018_set_pin(i2c_master_dev_handle_t dev_handle, uint8_t pin, uint8_t value)
{ {
ESP_LOGI(TAG_MCP, "Setting %d to %d", pin, value);
esp_err_t ret = ESP_FAIL; esp_err_t ret = ESP_FAIL;
if (pin < 8) if (pin < 8)
{ {

View File

@@ -26,7 +26,7 @@ void mcp3550_spi_init()
// .queue_size = 1, // .queue_size = 1,
// }; // };
// ESP_ERROR_CHECK(spi_bus_add_device(SPI2_HOST, &devcfg, &mcp3550_handle)); // ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_add_device(SPI2_HOST, &devcfg, &mcp3550_handle));
// Set MISO pin for input (needed for polling) // Set MISO pin for input (needed for polling)
gpio_set_direction(MCP3550_MISO_GPIO, GPIO_MODE_INPUT); gpio_set_direction(MCP3550_MISO_GPIO, GPIO_MODE_INPUT);
@@ -132,9 +132,13 @@ int32_t mcp3550_read(uint8_t cs_pin)
int64_t start = esp_timer_get_time(); int64_t start = esp_timer_get_time();
uint32_t timeout_us = MCP3550_TIMEOUT_MS * 1000; uint32_t timeout_us = MCP3550_TIMEOUT_MS * 1000;
ESP_LOGI(TAG_MCP, "Starting read from ADC CS %d", cs_pin);
// CS LOW // CS LOW
mcp23018_set_pin(MCP23018_DEV_HANDLE, cs_pin, 0); mcp23018_set_pin(MCP23018_DEV_HANDLE, cs_pin, 0);
vTaskDelay(pdMS_TO_TICKS(10));
// Wait for DR (MISO LOW) // Wait for DR (MISO LOW)
while (gpio_get_level(MCP3550_MISO_GPIO)) { while (gpio_get_level(MCP3550_MISO_GPIO)) {
if ((esp_timer_get_time() - start) > timeout_us) { if ((esp_timer_get_time() - start) > timeout_us) {

View File

@@ -37,7 +37,7 @@ void app_main(void)
ESP_LOGI("BOOT", "BRN Systems incorporated CanSat flight firmware build at %s %s", __DATE__, __TIME__); ESP_LOGI("BOOT", "BRN Systems incorporated CanSat flight firmware build at %s %s", __DATE__, __TIME__);
/* instantiate i2c master bus 0 */ /* instantiate i2c master bus 0 */
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c0_bus_cfg, &i2c0_bus_hdl)); ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_new_master_bus(&i2c0_bus_cfg, &i2c0_bus_hdl));
// spi_bus_config_t MCPBusCfg = { // spi_bus_config_t MCPBusCfg = {
// .mosi_io_num = -1, // .mosi_io_num = -1,
@@ -47,7 +47,7 @@ void app_main(void)
// .quadhd_io_num = -1, // .quadhd_io_num = -1,
// .max_transfer_sz = 4, // .max_transfer_sz = 4,
// }; // };
// ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &MCPBusCfg, SPI_DMA_DISABLED)); // ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_initialize(SPI2_HOST, &MCPBusCfg, SPI_DMA_DISABLED));
gpio_pullup_en(HSPI_MISO_GPIO); gpio_pullup_en(HSPI_MISO_GPIO);
gpio_pullup_en(HSPI_SD_CS); gpio_pullup_en(HSPI_SD_CS);
@@ -60,10 +60,10 @@ void app_main(void)
.quadhd_io_num = -1, .quadhd_io_num = -1,
.max_transfer_sz = 64, // probably change .max_transfer_sz = 64, // probably change
}; };
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &HighSpeedBusCfg, SPI_DMA_CH_AUTO)); ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_initialize(SPI3_HOST, &HighSpeedBusCfg, SPI_DMA_CH_AUTO));
/* scan i2c devices on i2c master bus 0 and print results */ /* scan i2c devices on i2c master bus 0 and print results */
ESP_ERROR_CHECK(i2c_master_bus_detect_devices(i2c0_bus_hdl)); ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_bus_detect_devices(i2c0_bus_hdl));
mcp23018_init(); mcp23018_init();

View File

@@ -426,39 +426,39 @@ static inline esp_err_t bme680_get_cal_factors(bme680_handle_t handle) {
ESP_ARG_CHECK( handle ); ESP_ARG_CHECK( handle );
/* bme680 attempt to request T1-T3 calibration values from device */ /* bme680 attempt to request T1-T3 calibration values from device */
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0xe9, &handle->dev_cal_factors->par_T1) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0xe9, &handle->dev_cal_factors->par_T1) );
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0x8a, (uint16_t *)&handle->dev_cal_factors->par_T2) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x8a, (uint16_t *)&handle->dev_cal_factors->par_T2) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0x8c, (uint8_t *)&handle->dev_cal_factors->par_T3) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x8c, (uint8_t *)&handle->dev_cal_factors->par_T3) );
/* bme680 attempt to request H1-H7 calibration values from device */ /* bme680 attempt to request H1-H7 calibration values from device */
ESP_ERROR_CHECK( bme680_i2c_read_from(handle, 0xe2, rx, BIT16_UINT8_BUFFER_SIZE) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_from(handle, 0xe2, rx, BIT16_UINT8_BUFFER_SIZE) );
handle->dev_cal_factors->par_H1 = (uint16_t)(((uint16_t)rx[1] << 4) | (rx[0] & 0x0F)); handle->dev_cal_factors->par_H1 = (uint16_t)(((uint16_t)rx[1] << 4) | (rx[0] & 0x0F));
ESP_ERROR_CHECK( bme680_i2c_read_from(handle, 0xe1, rx, BIT16_UINT8_BUFFER_SIZE) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_from(handle, 0xe1, rx, BIT16_UINT8_BUFFER_SIZE) );
handle->dev_cal_factors->par_H2 = (uint16_t)(((uint16_t)rx[0] << 4) | (rx[1] >> 4)); handle->dev_cal_factors->par_H2 = (uint16_t)(((uint16_t)rx[0] << 4) | (rx[1] >> 4));
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xe4, (uint8_t *)&handle->dev_cal_factors->par_H3) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xe4, (uint8_t *)&handle->dev_cal_factors->par_H3) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xe5, (uint8_t *)&handle->dev_cal_factors->par_H4) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xe5, (uint8_t *)&handle->dev_cal_factors->par_H4) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xe6, (uint8_t *)&handle->dev_cal_factors->par_H5) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xe6, (uint8_t *)&handle->dev_cal_factors->par_H5) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xe7, &handle->dev_cal_factors->par_H6) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xe7, &handle->dev_cal_factors->par_H6) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xe8, (uint8_t *)&handle->dev_cal_factors->par_H7) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xe8, (uint8_t *)&handle->dev_cal_factors->par_H7) );
/* bme680 attempt to request P1-P10 calibration values from device */ /* bme680 attempt to request P1-P10 calibration values from device */
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0x8e, &handle->dev_cal_factors->par_P1) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x8e, &handle->dev_cal_factors->par_P1) );
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0x90, (uint16_t *)&handle->dev_cal_factors->par_P2) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x90, (uint16_t *)&handle->dev_cal_factors->par_P2) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0x92, (uint8_t *)&handle->dev_cal_factors->par_P3) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x92, (uint8_t *)&handle->dev_cal_factors->par_P3) );
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0x94, (uint16_t *)&handle->dev_cal_factors->par_P4) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x94, (uint16_t *)&handle->dev_cal_factors->par_P4) );
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0x96, (uint16_t *)&handle->dev_cal_factors->par_P5) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x96, (uint16_t *)&handle->dev_cal_factors->par_P5) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0x99, (uint8_t *)&handle->dev_cal_factors->par_P6) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x99, (uint8_t *)&handle->dev_cal_factors->par_P6) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0x98, (uint8_t *)&handle->dev_cal_factors->par_P7) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x98, (uint8_t *)&handle->dev_cal_factors->par_P7) );
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0x9c, (uint16_t *)&handle->dev_cal_factors->par_P8) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x9c, (uint16_t *)&handle->dev_cal_factors->par_P8) );
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0x9e, (uint16_t *)&handle->dev_cal_factors->par_P9) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x9e, (uint16_t *)&handle->dev_cal_factors->par_P9) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xa0, &handle->dev_cal_factors->par_P10) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xa0, &handle->dev_cal_factors->par_P10) );
/* bme680 attempt to request G1-G3 calibration values from device */ /* bme680 attempt to request G1-G3 calibration values from device */
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xed, (uint8_t *)&handle->dev_cal_factors->par_G1) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xed, (uint8_t *)&handle->dev_cal_factors->par_G1) );
ESP_ERROR_CHECK( bme680_i2c_read_word_from(handle, 0xeb, (uint16_t *)&handle->dev_cal_factors->par_G2) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0xeb, (uint16_t *)&handle->dev_cal_factors->par_G2) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0xee, (uint8_t *)&handle->dev_cal_factors->par_G3) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xee, (uint8_t *)&handle->dev_cal_factors->par_G3) );
/* bme680 attempt to request gas range and switching error values from device */ /* bme680 attempt to request gas range and switching error values from device */
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0x02, &handle->dev_cal_factors->res_heat_range) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x02, &handle->dev_cal_factors->res_heat_range) );
handle->dev_cal_factors->res_heat_range = (handle->dev_cal_factors->res_heat_range & 0x30) / 16; handle->dev_cal_factors->res_heat_range = (handle->dev_cal_factors->res_heat_range & 0x30) / 16;
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0x00, (uint8_t *)&handle->dev_cal_factors->res_heat_val) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x00, (uint8_t *)&handle->dev_cal_factors->res_heat_val) );
ESP_ERROR_CHECK( bme680_i2c_read_byte_from(handle, 0x04, (uint8_t *)&handle->dev_cal_factors->range_switching_error) ); ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x04, (uint8_t *)&handle->dev_cal_factors->range_switching_error) );
handle->dev_cal_factors->range_switching_error = (handle->dev_cal_factors->range_switching_error & 0xf0) / 16; handle->dev_cal_factors->range_switching_error = (handle->dev_cal_factors->range_switching_error & 0xf0) / 16;
/* /*