Questions about starting 1701 and 1452 i2c with STM32
我正在尝试使用 stm32 启动 1701 和 1452。我第一次尝试用 i2c 启动 1701,但失败了。如果再尝试用i2吃饭,1452会启动失败。再次尝试用spi启动1452,成功了。我会附上我的编程代码帮助分析错误。
void vStartTask( void *pvParameters )
{
{
SIGMA_RESET();
default_download_IC_1();
while(1)
{
// printf("%d\r\n", ETH_ReadPHYRegister(0x00,1));
// Test();
// vTaskDelay(1000 / portTICK_RATE_MS);
}
//vTaskDelete(NULL);
}
}
如下代码所示,我可以用SPI启动1452,i2c的写法和SPI一样。每写入两个字节,地址就会增加。我认为写作应该没有问题。i2c有问题。
#define USE_SPI 0
void SIGMA_WRITE_REGISTER_BLOCK(int devAddress,int address,int length,ADI_REG_TYPE *pData)
{
uint8_t MSByte = 0,i;
uint8_t LSByte = 0;
uint16_t bytesSent = 0;
// Run until all bytes are sent
while(bytesSent < length)
{
#if USE_SPI
//Convert address to 8-bit
MSByte = address >> 8;
LSByte = (uint8_t)address & 0xFF;
/* Enable write operations */
GPIO_WriteBit(USBI_SPI_CS_GPIO_Port, USBI_SPI_CS_Pin, 0);
// vTaskDelay(10 / portTICK_RATE_MS);
/* dispatch orders */
SPI1_ReadWriteByte(0x00);
SPI1_ReadWriteByte(MSByte);
SPI1_ReadWriteByte(LSByte);
/* data transmission */
for( i = 0; i < 2; i++) // Send 2 bytes
{
SPI1_ReadWriteByte(pData[bytesSent]);
bytesSent++;
}
// SPI1_WriteByte(pData,length);
GPIO_WriteBit(USBI_SPI_CS_GPIO_Port, USBI_SPI_CS_Pin, 1);
address++;
if(bytesSent == length) break;
#else
//Convert address to 8-bit
MSByte = address >> 8;
LSByte = (uint8_t)address & 0xFF;
IIC_Start(); //I2c startup
IIC_Send_Byte(0x76);
IIC_Send_Byte(MSByte); // Send High Address
IIC_Send_Byte(LSByte) ; //Send low address
for( i = 0; i < 2; i++) // Send 2 bytes
{
IIC_Send_Byte(pData[bytesSent]);
bytesSent++;
}
IIC_Stop();//I2c stop
address++; // Increase address
#endif
}
}
The following is to set the start communication and end communication of i2c according to the data manual. I don't know if there is any error. It is also the same as SPI. Each time two bytes are sent, an address is added.
//Generate IIC start signal
void IIC_Start(void)
{
SDA_OUT(); //Sda cable output
IIC_SDA(1);
IIC_SCL(1);
delay_us(10);
IIC_SDA(0);//START:when CLK is high,DATA change form high to low
delay_us(10);
// IIC_SCL(0);//Clamp the I2C bus and prepare to send or receive data
}
//Generate IIC stop signal
void IIC_Stop(void)
{
SDA_OUT();//Sda cable output
IIC_SCL(0);
IIC_SDA(0);//STOP:when CLK is high DATA change form low to high
delay_us(10);
IIC_SCL(1);
delay_us(10);
IIC_SDA(1);//Send I2C bus end signal
delay_us(10);
}
void IIC_Send_Byte(u8 txd)
{
u8 t;
SDA_OUT();
for(t=0;t<8;t++)
{
IIC_SCL(0);//Pull down the clock to start data transmission
if(((txd&0x80)) == 1)
IIC_SDA(1);
else
IIC_SDA(0);
txd <<= 1;
delay_us(10);
IIC_SCL(1);
delay_us(10);
IIC_SCL(0);
delay_us(10);
}
}
The i2c address is 0x76. I used the same address as 0x76 to write the i2c address to 1452 through the i2c using the USB. Therefore, there should be no error in the i2c address. So what is the cause of the i2c startup failure of 1701 and 1452. 1452 spi started normally.
Audio Signal Processors
adau1452
software
4.7
SigmaDSP Audio Processors
1701and1452
adau1701
Show More
Hello liangsea,
Are you using our Eval board?
Can you please attach your hardware set up?
liangsea said:
he i2c address is 0x76. I used the same address as 0x76 to write the i2c address to 1452 through the i2c using the USB. Therefore, there should be no error in the i2c address
If the stm32 uses 7-bit I2C addressing, then your address will not be 0x76. it should be 0x3B. please verify that with stm32 documentation.
Regards,
Harish
Please log in to reply.