本帖最后由 swaggy 于 2018-5-31 10:44 编辑
我需要把一个使用I2C时序的温度传感器ADT7420接上AHB总线。由于vivado中没有直接I2C转AHB的ip核,于是将ahb转axi、axi转iic两个ip核连在一起,如下图所示:
顶层文件调用如下:
assign SCL = iic_rtl_scl_t ? iic_rtl_scl_o : 1'bz;
assign SDA = iic_rtl_sda_t ? iic_rtl_sda_o : 1'bz;
assign iic_rtl_scl_i = SCL;
assign iic_rtl_sda_i = SDA;
SENSOR_T SENSOR_T(
.HSEL(hsel_t),
.HCLK(fclk),
.HRESETn(reg_sys_rst_n),
.HREADY(hreadys),
.HADDR(haddrs),
.HTRANS(htranss),
.HWRITE(hwrites),
.HSIZE(hsizes),
.HWDATA(hwdatas),
.HREADYOUT(hreadyout_t),
.HRDATA(hrdata_t),
// .SCL(SCL),
// .SDA(SDA)
.iic_rtl_scl_i(iic_rtl_scl_i),
.iic_rtl_sda_i(iic_rtl_sda_i),
.iic_rtl_scl_o(iic_rtl_scl_o),
.iic_rtl_sda_o(iic_rtl_sda_o),
.iic_rtl_scl_t(iic_rtl_scl_t),
.iic_rtl_sda_t(iic_rtl_sda_t)
);
i2c的输入输出接口如下:
这几个输入输出之间的关系是什么。
按照使用文档上的操作时序,我使用了dynamic logic controller flow的工作模式
在keil上进行如上配置,
#include <stdint.h>
#define LED *(unsigned int *) 0x50000000
#define TEM_ISR 0x51000020
#define TEM_CR 0x5100100
#define TEM_IER 0x51000028
#define TEM_SR 0x51000104
#define TEM_TX_FIFO 0x51000108
#define TEM_RX_FIFO 0x5100010C
#define TEM_RX_PIRQ 0x51000120
#define TEM_RX_FIFO_OCY 0x51000118
#define TEM_TX_FIFO_OCY 0x51000114
void delay(uint32_t y);
int main(void)
{
static uint8_t i = 0;
static uint8_t l=0x01; volatile uint32_t temp = 0;
volatile uint32_t temp1 = 0;
while(1){
*(unsigned int *) TEM_IER=0xFF;
*(unsigned int *) TEM_RX_PIRQ=0x0F;
*(unsigned int *)TEM_CR|=0x2;
*(uint32_t *) TEM_TX_FIFO =0x197;
*(uint32_t *) TEM_TX_FIFO =0x201;
//temp = *(unsigned int *) TEM_RX_FIFO;
LED =0x55;
temp=*(unsigned int *)TEM_IER;
//temp=1;
//temp1=*(unsigned int *) TEM_ISR;
//delay(10);
*(unsigned int *)TEM_CR|=0x4;
delay(10);
//temp1=*(unsigned int *) TEM_ISR;
//temp1=*(unsigned int *) TEM_ISR;
do{
temp1=*(unsigned int *) TEM_ISR;
}while((temp1 & 0x8)==0);
*(unsigned int *) TEM_CR=0x00000010;
temp = *(unsigned int *) TEM_RX_FIFO;
delay(100);
l=l<<1;
if(l==0){
l=0x01;
}
i++;
}
}
在进行调试时scl与sda都无波形出现。
附上axi iic的使用文档。
http://bbs.eeworld.com.cn/forum.php?mod=attachment&aid=MzU3MjMzfDJiYTc4NWYyYmExYTA1YTg0MmQxZTM0MDE0M2IyMDljfDE1NTM0MzQxNTU%3D&request=yes&_f=.pdf
不胜感激!
一周热门 更多>