Part Number:ADS1119
Hello, everybody
MCU communicates with ADS1119 chip through analog IIC, and the data converted by the chip is always equal to 0,I don't know what the problem is.
IIC source code:
#include "iic.h"
#include "main.h"
#include "stm32f4xx_hal.h"
#include "stdio.h"
//#include "delay.h"
#define IIC_SDA_1 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_SET)
#define IIC_SDA_0 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_RESET)
#define IIC_SCL_1 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_SET)
#define IIC_SCL_0 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_RESET)
#define IIC_SDA_READ HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_11)
void iic_init(void)//
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
IIC_SDA_1;
IIC_SCL_1;
}
void iic_start(void)
{
SDA_OUT();
IIC_SDA_1;
IIC_SCL_1;
delay_us(100);
IIC_SDA_0;
delay_us(100);
IIC_SCL_0;
delay_us(100);
}
void iic_stop(void)
{
SDA_OUT();
IIC_SDA_0;
delay_us(100);
IIC_SCL_1;
delay_us(100);
IIC_SDA_1;
delay_us(100);
}
void ack(void)//主机应答
{
SDA_OUT();
IIC_SDA_0;
delay_us(100);
IIC_SCL_1;
delay_us(100);
IIC_SCL_0;
delay_us(100);
IIC_SDA_1;
}
void noack(void)
{
SDA_OUT();
IIC_SDA_1;
delay_us(100);
IIC_SCL_1;
delay_us(100);
IIC_SCL_0;
delay_us(100);
IIC_SDA_0;
}
uint8_t wait_ack(void)
{
uint8_t wo,a;
SDA_OUT();
IIC_SDA_1;
delay_us(100);
IIC_SCL_1;
delay_us(100);
SDA_IN();
if(IIC_SDA_READ)
{
wo = 1;
}
else
{
wo = 0;
}
IIC_SCL_0;
return wo;
}
void iic_write(uint8_t cmd)
{
SDA_OUT();
IIC_SCL_0;
for(uint8_t i = 0;i < 8;i++)
{ if(cmd&0x80)
IIC_SDA_1;
else
IIC_SDA_0; cmd<<=1; IIC_SCL_1;
delay_us(100); IIC_SCL_0;
delay_us(100); } //}
uint8_t iic_read(void)
{
uint8_t i,a;
uint8_t val = 0;
SDA_IN();
for(i=0;i<8;i++)
{
IIC_SCL_1;
delay_us(100);
val=val<<1;
//if(GPIOB->IDR& GPIO_IDR_IDR7)
if(IIC_SDA_READ)
{
val|=0x01;
}
IIC_SCL_0;
delay_us(100);
}
return val;
}
void SDA_OUT(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void SDA_IN(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
Amy Luo:
您好,
现在您可以写入寄存器并正确读出来了,是吗,您可以把您的寄存器配置读出来贴出来吗?
您的设备地址配置的是1000101吗?您输入的信号是什么?您可以把您的原理图也贴出来吗
,
LULE KEVIN:
hi
I can read the value of the register,Configuration register 0x65
,
LULE KEVIN:
hi
This is the schematic diagram
,
Amy Luo:
抱歉回复晚了,我看到您在下面链接重新发了个帖,请回复那个链接,我会在那个链接跟进您的问题,谢谢
https://e2echina.ti.com/support/data-converters/f/data-converters-forum/204419/ads1119-ads1119