So here's the new declaration block:
uint16_t devAddW = 0b1000000000000000; // // device address W because (ends with bit 0 for write mode) shifted to right
uint8_t data[8]; // data array
uint16_t dataLength; // size that has to be transmitted
uint32_t tickMem; // last recorded tick
uint16_t delay = 200; // time delay (ms)
No, no, no. It's a int16 because you can use larger addressing.
You can call a function passing an 8-bit value, no matter if the function use 8,16,32bit input value.
It'lll copy the value, it's fine.
What you can't do, for example, is passing a 8-bit pointer to a function expecting a 16 bit pointer.
Your config and your device use 7-bit address, so keep using:
uint8_t devAddW = (0b1000000 <<1 );
That address is only set when AD0 and AD1 pins are tied to ground, have you checked that?
HAL will use only the lower byte because it's configured in 7-bit addressing mode.
To send/receive raw data:
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
* the configuration information for the specified I2C.
* @param DevAddress Target device address: The device 7 bits address value
* in datasheet must be shifted to the left before calling the interface
* @param pData Pointer to data buffer
* @param Size Amount of data to be sent
* @param Timeout Timeout duration
* @retval HAL status
HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
However, if you want to read or write to a specific register, it will fail, because it sends Start/Stops on every call.
Ex. you can't do:
HAL_I2C_Master_Transmit(MAX_Addr, command)And then
HAL_I2C_Master_Receive(MAX_Addr, data)And expect you'll get the data from the first command.
The I2C device is unselected between these calls because there was a Stop condition, so every call is a new transaction.
You must send MAX6956_Addresss, cmd and transfer/receive data, all in a single transaction.
To read/write to a specific memory address (register), use:
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
* the configuration information for the specified I2C.
* @param DevAddress Target device address: The device 7 bits address value
* in datasheet must be shifted to the left before calling the interface
* @param MemAddress Internal memory address
* @param MemAddSize Size of internal memory address
* @param pData Pointer to data buffer
* @param Size Amount of data to be sent
* @param Timeout Timeout duration
* @retval HAL status
HAL_I2C_Mem_Write(hi2c, DevAddress, MemAddress, MemAddSize, pData, Size, Timeout)
HAL_I2C_Mem_Read(hi2c, DevAddress, MemAddress, MemAddSize, pData, Size, Timeout)
DevAddress is (MAX6956_Addresss<<1)
MemAddress is MAX6956 Command byte.
Command byte is 8-bit, so use I2C_MEMADD_SIZE_8BIT for MemAddSize.
pData is a pointer to your data.
Size is is number of pData bytes to send.
Ex. Writing 0x0F(16/16 current, 24mA) to Global Current register (0x02)
uint8_t data=0x0F;
HAL_I2C_Mem_Write(&hi2c1,MAX_Addr, 0x02, I2C_MEMADD_SIZE_8BIT, &data, 1, 100 )1=1 data byte to send, 100=100ms timeout (1ms should be already more than enough)
All these functions run start and stop conditions, no need to manually do them.