1、VIVADO下建立工程
其中iic控制器选择7bit 100k 其他默认
2、生成bit导入sdk
建立xilinx工程,使用hello world模板
需改源代码
#include <stdio.h>
#include “platform.h”
#include “xparameters.h”
#include “xil_printf.h”
#include “xil_io.h”
#include “xiic.h”
#include “xiic_l.h”
#include “sleep.h”
int main()
{
u8 i;
u8 j;
u32 status;
u32 data[4];
while(1)
{
usleep(20000);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_RFD_REG_OFFSET,0x01);//设置接收fifo深度
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_CR_REG_OFFSET,0x02);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_CR_REG_OFFSET,0x01);
while(Xil_In32(XPAR_IIC_0_BASEADDR+XIIC_SR_REG_OFFSET) != 0xc0)
{}
usleep(20000);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x1a2);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x04+04*j);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x12+j);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x34+j);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x56+j);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x278);
while((Xil_In32(XPAR_IIC_0_BASEADDR+XIIC_SR_REG_OFFSET) & XIIC_SR_TX_FIFO_EMPTY_MASK) >> 7 != 1)
{}
usleep(20000);
while(Xil_In32(XPAR_IIC_0_BASEADDR+XIIC_SR_REG_OFFSET) != 0xc0)
{}
usleep(20000);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x1a2);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x04*j);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x1a3);
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_DTR_REG_OFFSET,0x204);
for(i=0;i<4;i++)
{
while((Xil_In32(XPAR_IIC_0_BASEADDR+XIIC_SR_REG_OFFSET) & XIIC_SR_RX_FIFO_EMPTY_MASK) >> 6 == 1)
{}
usleep(20000);
data[i] = Xil_In32(XPAR_IIC_0_BASEADDR+XIIC_DRR_REG_OFFSET);
}
Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_RESETR_OFFSET,0x0a);//复位iic
j++;
}
}
在Xil_Out32(XPAR_IIC_0_BASEADDR+XIIC_RESETR_OFFSET,0x0a);//复位iic设置断点,则可烧录,开始运行程序。
现象,每次写入4B数据,每次读取4B数据。