...
1.2 - Creating a task and setting a GPIO
Create a task to run your LEDs. We learned how to create tasks in FW 102, so take a look there to refresh on how to do that.
...
Setting the config to continuous mode - The call to I2C write register is done for you, what you need to figure out is what value to actually write. Head to page 28 and 29 of the datasheet. Table 8 lays out what each bit means within the 16-bit configuration value. Your job is to construct what 16 bits we’re writing to the ADC by reading the table. Here’s the steps:
Leave most things as default except for the Field “MODE”. Set this bit to a 0.
To do this, look at the value in the “Bit” column. This is the bit number the Field corresponds to. For “OS”, it is defined by just 1 bit, bit 15. See below that when writing out binary, bit 15 is the most significant (to the left) and bit 0 is the least (all the way to the right).
| 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Completing the read raw function - You’ll need to use the
i2c.h
header to include some I2C functions in your code. To read from the ADC, use the functioni2c_read_reg
and the appropriate arguments. The arguments are as follows:Port: The function signature contains a
config
struct. The struct has a memberi2c_port
so use this value as the port argument.Address: Same as the port, use the
i2c_addr
member as the address argument.Register: Look at
ads1115.h
. Within theADS1115_Reg
enum, there’s a list of registers. You want to read from the conversion register, so use that value as the argument.Buffer/reading: This is the buffer to which the converted value is read into. Pass the reading pointer into this.
Bytes: This is the number of bytes of data you want to read back. How many bytes are in a
uint16_t
?
Completing the read converted function - The ADC gives you a value between 0 and 65535, which is the
uin16_t
max value. Let’s assume in this driver that this represents a reading between 0 -2.048V and 2.048V (as we had set in the config register). How would you convert the “raw” reading to a voltage? (Hint: think about what a reading of 1 means, that would be 1/65535 of 24.048V096V. Use that logic to convert the readings.
...