Hi guys,
I've been going around doing some research on how i can
get an i2c on working using avr-gcc and C programming.
so far so good.. I've been able to understand the setting up of the
i2c and initializing it thanks some codes online.
I've made use of i2c using the Raspberry pico just to get a feel
of the communication process. Things are pretty straight forward
with the Pico since Raspberry PI offers a very good explanation of their peripherals.
I've come across this particular example which is very interesting but just need to understand something.
I've asked this question on avrfreaks but unfortunately they didn't know the answer. they suggested i do some trials errors until i find out what works and what doesn't which i believe is a good idea but assuming this is how the i2c protocol works on the Attiny then I'd still need to figure this out before i can move forward.
first pay attention to this Raspberry Pico code example:
// this is a raspberrypi pico i2c function
int i2c_write_blocking (i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop)
/**************************/
So with this, I have this:
// By default the device address is 0x36
static int addr = 0x36; // device address
uint8_t buffer[2] = {0};
static void get_VERSION()
{
uint8_t VERSION = 0x08;
uint16_t version;
i2c_write_blocking(I2C_PORT, addr, &VERSION, 1, true);
i2c_read_blocking(I2C_PORT, addr, buffer, 2, false);
version = buffer[0] << 8 | buffer[1];
printf("Device version: %d \n", (int16_t)version);
// Device version: 0x%04x\n
}
this little function is self-explanatory based on it's name.
As an i2c protocol goes, there needs to be a Write before a Read
So in my case i'm getting the device version thus a Write is first performed followed by a Read.
Now ignoring the first and last parameters we have:
i2c_write_blocking(*, device address, register address, byte length, *);
Looking back at my code, I'm only getting the device address thus the register address points to the location of the data i want and i then perform a Read.
Again.. I'm NOT! writing to the device to reset itself, sleep or behave in a certain way, I'm only getting information from it.
NOW HERE'S THE CONFUSION
I came across this very interesting code example
Attiny series - 1 i2c example
which has similar function but with an extra parameter..
On the page, there's the Complete Code Example
section written in a dark mode editor,
there are the functions and with these parameters..
// Attiny series 0(maybe) , 1 and 2 code example
I2C_Write_Bytes(uint8_t dev_add, uint8_t reg_add, uint8_t *data, uint8_t len);
the *uint8_ data is my issue so Assuming that i was writing to the device to tell it to sleep or reset etc
then I'd probably do something like this for the Attiny:
uint8_t addr = 0x36;
static void Sleep(){
// sleep
uint8_t SLEEP = 0xFE;
uint8_t = buf[2] = {0xB9,0x02};
I2C_Write_Bytes(addr, SLEEP, buf, 2); // dev_add = addr, reg_add = SLEEP, *data = buf
}
But since I'm not telling it to go to sleep or anything,
what is the purpose of the uint8_t *data ??
my point is if i were to go back to the first code, above and try to get the device version then I know what is device address, the device register and the byte length but then what is the value of uint8_t *data or how would treat it ??
Thanks
