gps.cpp, lorawan.cpp: i2c bugfixes (issue #156)

This commit is contained in:
Klaus K Wilting 2018-09-20 13:23:22 +02:00
parent 6af4405e2b
commit a0377a315c
3 changed files with 28 additions and 20 deletions

View File

@ -53,7 +53,6 @@ void gps_loop(void *pvParameters) {
Wire.write(0x00); // dummy write to start read
Wire.endTransmission();
Wire.beginTransmission(GPS_ADDR);
while (cfg.gpsmode) {
Wire.requestFrom(GPS_ADDR | 0x01, 32);
while (Wire.available()) {
@ -61,8 +60,6 @@ void gps_loop(void *pvParameters) {
vTaskDelay(2 / portTICK_PERIOD_MS); // polling mode: 500ms sleep
}
}
// after GPS function was disabled, close connect to GPS device
Wire.endTransmission();
#endif // GPS Type
}

View File

@ -36,3 +36,7 @@
#define OLED_RST GPIO_NUM_16 // SSD1306 RST
#define I2C_SDA GPIO_NUM_4 // SD1306 D1+D2
#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

View File

@ -20,6 +20,8 @@ const lmic_pinmap lmic_pins = {.mosi = PIN_SPI_MOSI,
.rst = RST,
.dio = {DIO0, DIO1, DIO2}};
/* old version
// DevEUI generator using devices's MAC address
void gen_lora_deveui(uint8_t *pdeveui) {
uint8_t *p = pdeveui, dmac[6];
@ -37,7 +39,7 @@ 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
void gen_lora_deveui(uint8_t *pdeveui) {
@ -56,7 +58,6 @@ void gen_lora_deveui(uint8_t *pdeveui) {
*p++ = dmac[1];
*p++ = dmac[0];
}
*/
// Function to do a byte swap in a byte array
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) {
// read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
#ifdef MCP_24AA02E64_I2C_ADDRESS
uint8_t i2c_ret;
// Init this just in case, no more to 100KHz
Wire.begin(I2C_SDA, I2C_SCL, 100000);
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
i2c_ret = Wire.endTransmission();
// check if device seen on i2c bus
if (i2c_ret == 0) {
// check if device was seen on i2c bus
if (Wire.endTransmission() == 0) {
char deveui[32] = "";
uint8_t data;
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8);
Wire.endTransmission();
if (Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8)) {
while (Wire.available()) {
data = Wire.read();
sprintf(deveui + strlen(deveui), "%02X ", data);
*pdeveui++ = data;
}
i2c_ret = Wire.endTransmission();
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui);
ESP_LOGI(TAG, "Serial EEPROM found, read DEVEUI %s", deveui);
} else {
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret);
ESP_LOGI(TAG, "Could not read DEVEUI from serial EEPROM");
}
} else {
ESP_LOGI(TAG, "Could not find serial EEPROM on I2C bus");
}
// Set back to 400KHz to speed up OLED
Wire.setClock(400000);
#endif // MCP 24AA02E64