After working with arduino's and microprocessors like the ESP8266 and ESP32, I recently started toying around with a nRF52840 dev kit.
After going through some tutorials, I wanted to see if I can get a SGP30 air quality sensor to work (https://www.mouser.com/datasheet/2/682/Sensirion_Gas_Sensors_Datasheet_SGP30-2320451.pdf)
I have visual studio running with the nRF connect integration / SDK. I used the following sketch to scan for I2C devices:
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/
#include <zephyr.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <drivers/i2c.h>
#include <device.h>
#define TEST_BUF_SIZE 128
void main(void)
{
printk("The I2C scanner started\n");
const struct device *i2c_dev;
int error;
i2c_dev = device_get_binding("I2C_1");
if (!i2c_dev) {
printk("Binding failed.");
return;
}
/* Demonstration of runtime configuration */
i2c_configure(i2c_dev, I2C_SPEED_SET(I2C_SPEED_STANDARD));
printk("Value of NRF_TWIM2->PSEL.SCL : %d \n",NRF_TWIM1->PSEL.SCL);
printk("Value of NRF_TWIM2->PSEL.SDA : %d \n",NRF_TWIM1->PSEL.SDA);
printk("Value of NRF_TWIM2->FREQUENCY: %d \n",NRF_TWIM1->FREQUENCY);
printk("26738688 -> 100k\n");
for (uint8_t i = 4; i <= 0x7F; i++) {
struct i2c_msg msgs[1];
uint8_t dst = 1;
msgs[0].buf = &dst;
msgs[0].len = 1U;
msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;
// printk("Testing %2x", i);
error = i2c_transfer(i2c_dev, &msgs[0], 1, i);
if (error == 0) {
printk("0x%2x FOUND\n", i);
}
else {
// printk("error %d \n", error);
}
}
}
Which worked, the SGP30 was found on address 0x58.
With the nRF connect SDK, a driver is supplied for the SGP40, but unfortunately not for the SGP30.
I found a github repository from Sensirion where they have some code for Nordic nRF series: https://github.com/Sensirion/embedded-common/tree/master/i2c/sample-implementations/Nordic_nRF5_series , however, I am not sure how I should use it. I also found the NRF40 drivers that are included with the SDK, and thought that I might be able to replace it with the code from their repository, but it doesn't look like the SGP40 driver code at all.
So now I am a bit lost where I should go from here, any ideas?