A problem with I2C and ADS1115
I get always zeros from my code. Is there something you see immediately.
This is what TI tells me to do (I have ADS1115).
For example, to write to the configuration register to set the ADS111x to continuous-conversion mode and then
read the conversion result, send the following bytes in this order:
1. Write to Config register:
– First byte: 0b10010000 (first 7-bit I2C address followed by a low R/W bit)
– Second byte: 0b00000001 (points to Config register)
– Third byte: 0b10000100 (MSB of the Config register to be written)
– Fourth byte: 0b10000011 (LSB of the Config register to be written)
2. Write to Address Pointer register:
– First byte: 0b10010000 (first 7-bit I2C address followed by a low R/W bit)
– Second byte: 0b00000000 (points to Conversion register)
3. Read Conversion register:
– First byte: 0b10010001 (first 7-bit I2C address followed by a high R/W bit)
– Second byte: the ADS111x response with the MSB of the Conversion register
– Third byte: the ADS111x response with the LSB of the Conversion register
And this is my code to do it
unsigned char txBuffer[25];
unsigned char rxBuffer[25];
char msg[80];
int lamp1,lamp2;
...
...
...
txBuffer[0]=0b00000001 ;//
txBuffer[1]=0b10000100 ;
txBuffer[2] =0b10000011;
HAL_I2C_Master_Transmit (&hi2c1,(uint8_t)0b10010000,(uint8_t*)txBuffer, 3, 1000);
txBuffer[0]=0b00000000;//
HAL_I2C_Master_Transmit (&hi2c1, (uint8_t)0b10010000, (uint8_t*)txBuffer,1, 1000);
HAL_Delay(500);
txBuffer[0]=0b10010001 ;//
txBuffer[1]=0b00000001 ;//
txBuffer[2] =0b10000100;
txBuffer[2] =0b10000011;
HAL_I2C_Master_Receive (&hi2c1, (uint8_t)0b10010001, (uint8_t*)rxBuffer, 2, 1000);
lamp1=rxBuffer[0]*256;
lamp1=lamp1+(rxBuffer[1]);
sprintf(msg ,"01 06 21 adcanssi %d \r\n",lamp1);
HAL_UART_Transmit(&huart3, (uint8_t*)msg, strlen(msg), 1000);