gps.cpp, lorawan.cpp: i2c bugfixes (issue #156)
This commit is contained in:
parent
6af4405e2b
commit
a0377a315c
@ -5,7 +5,7 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = "main";
|
static const char TAG[] = "main";
|
||||||
|
|
||||||
TinyGPSPlus gps;
|
TinyGPSPlus gps;
|
||||||
gpsStatus_t gps_status;
|
gpsStatus_t gps_status;
|
||||||
|
|
||||||
// read GPS data and cast to global struct
|
// read GPS data and cast to global struct
|
||||||
@ -53,7 +53,6 @@ void gps_loop(void *pvParameters) {
|
|||||||
Wire.write(0x00); // dummy write to start read
|
Wire.write(0x00); // dummy write to start read
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
|
||||||
Wire.beginTransmission(GPS_ADDR);
|
|
||||||
while (cfg.gpsmode) {
|
while (cfg.gpsmode) {
|
||||||
Wire.requestFrom(GPS_ADDR | 0x01, 32);
|
Wire.requestFrom(GPS_ADDR | 0x01, 32);
|
||||||
while (Wire.available()) {
|
while (Wire.available()) {
|
||||||
@ -61,8 +60,6 @@ void gps_loop(void *pvParameters) {
|
|||||||
vTaskDelay(2 / portTICK_PERIOD_MS); // polling mode: 500ms sleep
|
vTaskDelay(2 / portTICK_PERIOD_MS); // polling mode: 500ms sleep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// after GPS function was disabled, close connect to GPS device
|
|
||||||
Wire.endTransmission();
|
|
||||||
|
|
||||||
#endif // GPS Type
|
#endif // GPS Type
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,8 @@
|
|||||||
// pin definitions for I2C interface of OLED Display
|
// pin definitions for I2C interface of OLED Display
|
||||||
#define OLED_RST GPIO_NUM_16 // SSD1306 RST
|
#define OLED_RST GPIO_NUM_16 // SSD1306 RST
|
||||||
#define I2C_SDA GPIO_NUM_4 // SD1306 D1+D2
|
#define I2C_SDA GPIO_NUM_4 // SD1306 D1+D2
|
||||||
#define I2C_SCL GPIO_NUM_15 // SD1306 D0
|
#define I2C_SCL GPIO_NUM_15 // SD1306 D0
|
||||||
|
|
||||||
|
// I2C config for Microchip 24AA02E64 DEVEUI unique address
|
||||||
|
#define MCP_24AA02E64_I2C_ADDRESS 0x50 // I2C address for the 24AA02E64
|
||||||
|
#define MCP_24AA02E64_MAC_ADDRESS 0xF8 // Memory adress of unique deveui 64 bits
|
@ -20,6 +20,8 @@ const lmic_pinmap lmic_pins = {.mosi = PIN_SPI_MOSI,
|
|||||||
.rst = RST,
|
.rst = RST,
|
||||||
.dio = {DIO0, DIO1, DIO2}};
|
.dio = {DIO0, DIO1, DIO2}};
|
||||||
|
|
||||||
|
/* old version
|
||||||
|
|
||||||
// DevEUI generator using devices's MAC address
|
// DevEUI generator using devices's MAC address
|
||||||
void gen_lora_deveui(uint8_t *pdeveui) {
|
void gen_lora_deveui(uint8_t *pdeveui) {
|
||||||
uint8_t *p = pdeveui, dmac[6];
|
uint8_t *p = pdeveui, dmac[6];
|
||||||
@ -37,13 +39,13 @@ void gen_lora_deveui(uint8_t *pdeveui) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The above function should be changed to this one, but this would be a breaking change
|
*/
|
||||||
|
|
||||||
// DevEUI generator using devices's MAC address
|
// DevEUI generator using devices's MAC address
|
||||||
void gen_lora_deveui(uint8_t *pdeveui) {
|
void gen_lora_deveui(uint8_t *pdeveui) {
|
||||||
uint8_t *p = pdeveui, dmac[6];
|
uint8_t *p = pdeveui, dmac[6];
|
||||||
ESP_ERROR_CHECK(esp_efuse_mac_get_default(dmac));
|
ESP_ERROR_CHECK(esp_efuse_mac_get_default(dmac));
|
||||||
// deveui is LSB, we reverse it so TTN DEVEUI display
|
// deveui is LSB, we reverse it so TTN DEVEUI display
|
||||||
// will remain the same as MAC address
|
// will remain the same as MAC address
|
||||||
// MAC is 6 bytes, devEUI 8, set middle 2 ones
|
// MAC is 6 bytes, devEUI 8, set middle 2 ones
|
||||||
// to an arbitrary value
|
// to an arbitrary value
|
||||||
@ -56,7 +58,6 @@ void gen_lora_deveui(uint8_t *pdeveui) {
|
|||||||
*p++ = dmac[1];
|
*p++ = dmac[1];
|
||||||
*p++ = dmac[0];
|
*p++ = dmac[0];
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Function to do a byte swap in a byte array
|
// Function to do a byte swap in a byte array
|
||||||
void RevBytes(unsigned char *b, size_t c) {
|
void RevBytes(unsigned char *b, size_t c) {
|
||||||
@ -98,29 +99,35 @@ void os_getDevEui(u1_t *buf) {
|
|||||||
void get_hard_deveui(uint8_t *pdeveui) {
|
void get_hard_deveui(uint8_t *pdeveui) {
|
||||||
// read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
|
// read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
|
||||||
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
uint8_t i2c_ret;
|
|
||||||
// Init this just in case, no more to 100KHz
|
// Init this just in case, no more to 100KHz
|
||||||
Wire.begin(I2C_SDA, I2C_SCL, 100000);
|
Wire.begin(I2C_SDA, I2C_SCL, 100000);
|
||||||
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
i2c_ret = Wire.endTransmission();
|
|
||||||
// check if device seen on i2c bus
|
// check if device was seen on i2c bus
|
||||||
if (i2c_ret == 0) {
|
if (Wire.endTransmission() == 0) {
|
||||||
char deveui[32] = "";
|
char deveui[32] = "";
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
|
|
||||||
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8);
|
Wire.endTransmission();
|
||||||
while (Wire.available()) {
|
|
||||||
data = Wire.read();
|
if (Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8)) {
|
||||||
sprintf(deveui + strlen(deveui), "%02X ", data);
|
while (Wire.available()) {
|
||||||
*pdeveui++ = data;
|
data = Wire.read();
|
||||||
|
sprintf(deveui + strlen(deveui), "%02X ", data);
|
||||||
|
*pdeveui++ = data;
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Serial EEPROM found, read DEVEUI %s", deveui);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Could not read DEVEUI from serial EEPROM");
|
||||||
}
|
}
|
||||||
i2c_ret = Wire.endTransmission();
|
|
||||||
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui);
|
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret);
|
ESP_LOGI(TAG, "Could not find serial EEPROM on I2C bus");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set back to 400KHz to speed up OLED
|
// Set back to 400KHz to speed up OLED
|
||||||
Wire.setClock(400000);
|
Wire.setClock(400000);
|
||||||
#endif // MCP 24AA02E64
|
#endif // MCP 24AA02E64
|
||||||
|
Loading…
Reference in New Issue
Block a user