2021-05-09 08:57 PM
I am trying to interface IC ADS1115(ADC) with STM32F401RE through I2C communication.I am not getting ACK from Slave after writing data to Config register.But getting ACK for device address(0x92) and also in I2C1->SR1 register AF-Acknowlege failure bit is getting set as attached below.Any kind of inputs would be appreciated.
void SystemInit()
{
RCC->CR|=RCC_HSION;
RCC->APB1ENR|=RCC_PWREN;
PWR->CR|=PWR_VOS;
RCC->CFGR|=RCC_SW;
}
void I2C_Config()
{
/* Master transmitter in standard mode*/
RCC->AHB1ENR |=2; /* Enabling clock for GPIOB port*/
RCC->APB1ENR |=1<<21; /*Enabling clock for I2C1 */
GPIOB->MODER =(2<<16) | (2<<18); /*Alternative function in PB8,PB9 SCL,SDA PINS*/
GPIOB->OTYPER |=1<<8; /*1: Output open-drain */
GPIOB->OTYPER |=1<<9; /*1: Output open-drain */
GPIOB->PUPDR |=1<<16; /*Pullup */
GPIOB->PUPDR |=1<<18; /* pullup */
GPIOB->AFR[1] =((4<<0) | (4<<4)); /* Alternate function low register is AF4 is I2C1 SCL */
GPIOB->OSPEEDR|=3<<16; /*High speed */
GPIOB->OSPEEDR|=3<<18; /*High speed */
I2C1->CR1 |=(1<<15);
I2C1->CR1 &=~(1<<15);
I2C1->SR2=0;
I2C1->SR1=0;
I2C1->CR2 |=16<<0; /*setting 16 Mhz as per APB1 Programming peripheral input clock */
I2C1->CCR |=80<<0; /*setting clock control register */
I2C1->TRISE =17<<0; /*Setting rise time */
I2C1->CR1|=1<<0; /*Enable Periperal Enable */
I2C1->CR1|=1<<10; /*Enable Acknowledgment */
}
void I2C_Start()
{
I2C1->CR1 |=1<<8 ; /*Enable Start condition*/
while(!(I2C1->SR1 & (1<<0)));/*Wait for SB bit to set */
}
void I2C_Write(uint8_t data)
{
while(!(I2C1->SR1 & (1<<7))) ;/* Wait for Bit 7 TxE: Data register empty */
I2C1->DR=data;
while(!(I2C1->SR1 & (1<<2)));/*Wait for the byte Tranfer */
}
void I2C_Address(uint8_t Address)
{
I2C1->DR=Address;
while(!(I2C1->SR1 & (1<<1)));/* wait for ADDR Bit 1 ADDR: Address sent*/
uint32_t temp =(I2C1->SR1 | I2C1->SR2);
}
void I2C_Stop()
{
I2C1->CR1 |=(1<<9);/*Bit 9 STOP: Stop generation*/
}
int main()
{
SystemInit();
I2C_Config();
I2C_Start();
I2C_Address(0x92);/*Device address */
I2C_Write(0x01);/*points to Config register*/
I2C_Write(0x84);/*MSB of the Config register to be written*/
I2C_Stop();
while(1);
}
2021-05-16 12:27 AM
Default address for ADS1115 is 0x4A (can be changed to 0x4B an so on...)
Shifted 1bit left for RW bit it gives 0x94/95 but no way 0x92. ADS ignores your requests.