revert mission timer to 32 bit, add signal level monitoring
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"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.openOcdConfigs": [
|
||||
"board/esp32s3-builtin.cfg"
|
||||
|
@@ -2,7 +2,7 @@ dependencies:
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 5.5.0
|
||||
version: 5.4.1
|
||||
k0i05/esp_bme680:
|
||||
component_hash: 2df0cb14d4425565a8745d4a96bfaa8ff7e90bbec3e208a073821406dded23c8
|
||||
dependencies:
|
||||
|
@@ -18,7 +18,7 @@ typedef struct __attribute__((packed))
|
||||
char syncPhrase[10]; //10
|
||||
uint32_t packetIndex; //14
|
||||
uint8_t packetType; //15
|
||||
uint64_t missionTimer; //19
|
||||
uint32_t missionTimer; //19
|
||||
uint32_t CRCCheck;
|
||||
} DownBoundPacket;
|
||||
|
||||
|
@@ -202,6 +202,7 @@ void prepare_and_send_telemetry(uint64_t missionTimer)
|
||||
fsync(fileno(csvFile)); // Critical: this ensures actual write to disk
|
||||
}
|
||||
|
||||
printf("Sending %d byte packet hehe\n", offset);
|
||||
send_packet_without_retries(bufOut, offset);
|
||||
packetReadiness = 0;
|
||||
}
|
||||
|
@@ -26,11 +26,11 @@ void gps_init()
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
|
||||
.rx_flow_ctrl_thresh = 122,
|
||||
};
|
||||
ESP_ERROR_CHECK(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_param_config(GPS_UART_NUM, &uart_config));
|
||||
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);
|
||||
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] == '$') {
|
||||
ESP_LOGI(TAG, "Received NMEA: %s", line);
|
||||
|
||||
if (strstr(line, "$GPGGA") == line) {
|
||||
if (strstr(line, "$GNGGA") == line) {
|
||||
parse_gpgga(line);
|
||||
parse_gpgga_to_struct(line, &gpsDataOut);
|
||||
} else if (strstr(line, "$GPRMC") == line) {
|
||||
|
@@ -8,21 +8,26 @@ i2c_device_config_t INA260_DEV_CFG = {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
esp_err_t ina260_init()
|
||||
{
|
||||
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,
|
||||
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;
|
||||
|
||||
// The register address is what we want to send first (the "transmit" part)
|
||||
@@ -35,11 +40,12 @@ esp_err_t i2c_master_read_register_transmit_receive(i2c_master_dev_handle_t devi
|
||||
|
||||
// Perform the combined write (register address) and read (register value)
|
||||
ret = i2c_master_transmit_receive(INA260_DEV_HANDLE,
|
||||
write_buffer, write_size,
|
||||
read_buffer, read_size,
|
||||
I2C_TIMEOUT_MS_VALUE);
|
||||
write_buffer, write_size,
|
||||
read_buffer, read_size,
|
||||
I2C_TIMEOUT_MS_VALUE);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
if (ret == ESP_OK)
|
||||
{
|
||||
// Copy the data from the temporary read buffer to the output buffer
|
||||
memcpy(data, read_buffer, read_size);
|
||||
}
|
||||
@@ -49,29 +55,32 @@ 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)
|
||||
{
|
||||
*volt = 0;
|
||||
*cur = 0;
|
||||
*pow = 0;
|
||||
for (uint8_t reg_addr = 1; reg_addr <= 3; reg_addr++)
|
||||
if (INA260_DEV_HANDLE)
|
||||
{
|
||||
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)));
|
||||
// Perform the register read
|
||||
switch (reg_addr)
|
||||
*volt = 0;
|
||||
*cur = 0;
|
||||
*pow = 0;
|
||||
for (uint8_t reg_addr = 1; reg_addr <= 3; reg_addr++)
|
||||
{
|
||||
case 1:
|
||||
*cur = (((uint16_t)(reg_value[0] & 0xFF)) << 8) | (reg_value[1] & 0xFF);
|
||||
//*cur = *((uint16_t *)reg_value);
|
||||
break;
|
||||
case 2:
|
||||
*volt = (((uint16_t)(reg_value[0] & 0xFF)) << 8) | (reg_value[1] & 0xFF);
|
||||
break;
|
||||
case 3:
|
||||
*pow = (((uint16_t)(reg_value[0] & 0xFF)) << 8) | (reg_value[1] & 0xFF);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
uint8_t reg_value[2] = {0}; // Buffer for storing register data
|
||||
|
||||
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
|
||||
switch (reg_addr)
|
||||
{
|
||||
case 1:
|
||||
*cur = (((uint16_t)(reg_value[0] & 0xFF)) << 8) | (reg_value[1] & 0xFF);
|
||||
//*cur = *((uint16_t *)reg_value);
|
||||
break;
|
||||
case 2:
|
||||
*volt = (((uint16_t)(reg_value[0] & 0xFF)) << 8) | (reg_value[1] & 0xFF);
|
||||
break;
|
||||
case 3:
|
||||
*pow = (((uint16_t)(reg_value[0] & 0xFF)) << 8) | (reg_value[1] & 0xFF);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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_LOGI(TAG_MCP, "Setting %d to %d", pin, value);
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
if (pin < 8)
|
||||
{
|
||||
|
@@ -26,7 +26,7 @@ void mcp3550_spi_init()
|
||||
// .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)
|
||||
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();
|
||||
uint32_t timeout_us = MCP3550_TIMEOUT_MS * 1000;
|
||||
|
||||
ESP_LOGI(TAG_MCP, "Starting read from ADC CS %d", cs_pin);
|
||||
|
||||
// CS LOW
|
||||
mcp23018_set_pin(MCP23018_DEV_HANDLE, cs_pin, 0);
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
// Wait for DR (MISO LOW)
|
||||
while (gpio_get_level(MCP3550_MISO_GPIO)) {
|
||||
if ((esp_timer_get_time() - start) > timeout_us) {
|
||||
|
@@ -37,7 +37,7 @@ void app_main(void)
|
||||
ESP_LOGI("BOOT", "BRN Systems incorporated CanSat flight firmware build at %s %s", __DATE__, __TIME__);
|
||||
|
||||
/* 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 = {
|
||||
// .mosi_io_num = -1,
|
||||
@@ -47,7 +47,7 @@ void app_main(void)
|
||||
// .quadhd_io_num = -1,
|
||||
// .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_SD_CS);
|
||||
@@ -60,10 +60,10 @@ void app_main(void)
|
||||
.quadhd_io_num = -1,
|
||||
.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 */
|
||||
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();
|
||||
|
||||
|
@@ -426,39 +426,39 @@ static inline esp_err_t bme680_get_cal_factors(bme680_handle_t handle) {
|
||||
ESP_ARG_CHECK( handle );
|
||||
|
||||
/* 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( 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_word_from(handle, 0xe9, &handle->dev_cal_factors->par_T1) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x8a, (uint16_t *)&handle->dev_cal_factors->par_T2) );
|
||||
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 */
|
||||
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));
|
||||
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));
|
||||
ESP_ERROR_CHECK( 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( 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( 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, 0xe4, (uint8_t *)&handle->dev_cal_factors->par_H3) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( 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, 0xe6, (uint8_t *)&handle->dev_cal_factors->par_H5) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0xe7, &handle->dev_cal_factors->par_H6) );
|
||||
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 */
|
||||
ESP_ERROR_CHECK( 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( 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( 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( 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( 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_word_from(handle, 0x8e, &handle->dev_cal_factors->par_P1) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0x90, (uint16_t *)&handle->dev_cal_factors->par_P2) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_byte_from(handle, 0x92, (uint8_t *)&handle->dev_cal_factors->par_P3) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( 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, 0x96, (uint16_t *)&handle->dev_cal_factors->par_P5) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( 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, 0x98, (uint8_t *)&handle->dev_cal_factors->par_P7) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( 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, 0x9e, (uint16_t *)&handle->dev_cal_factors->par_P9) );
|
||||
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 */
|
||||
ESP_ERROR_CHECK( 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( 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, 0xed, (uint8_t *)&handle->dev_cal_factors->par_G1) );
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT( bme680_i2c_read_word_from(handle, 0xeb, (uint16_t *)&handle->dev_cal_factors->par_G2) );
|
||||
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 */
|
||||
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;
|
||||
ESP_ERROR_CHECK( 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, 0x00, (uint8_t *)&handle->dev_cal_factors->res_heat_val) );
|
||||
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;
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user