VC707开发板的IIC控制
程序员文章站
2024-02-23 23:04:46
...
VC707开发板的IIC控制
最近学习VC707的使用,需要用到VC707的FMC接口,因此涉及到IIC控制,作为笔记简单记录一下。
VC707开发板上的IIC连接方式
通过VC707开发板的开发文档,了解到开发板上的IIC连接方式如下:
首先,左侧的是FPGA开发板上的默认IIC引脚,通过一组引脚(AT35、AU32)引出,连接到板上一块TI的芯片(PCA9548),这块芯片作为IIC路由,再进一步连接到开发板上的各类IIC设备(FMC、EEPROM、HDMI芯片等)。
硬件连接
提供一种相对简单的连接方式——使用AXI IIC IP核:
这个IP核是AXI4-Lite接口控制的IIC控制IP,通过AXI Interconnect连接到MicroBlaze的M_AXI_DP接口,此处省略。
在IP核的设置选项中,选择IIC_main,系统会自动根据VC707开发板的默认配置分配到iic_main的引脚(AT35、AU32)。
SDK开发过程
从VC707的官方文档了解到,由于使用了路由芯片(PCA9548),在使用时需要做一些特别处理:
配置路由芯片
0x74(0b1110100)位置的寄存器为路由芯片的选择寄存器,需要通过配置才能选中对应的iic设备,具体对应规则如下:
SDK实现代码如下,其中变量select就是写入0x74地址的内容,可以根据需要进行调整。
#define TESTAPP_GEN
#include "xparameters.h"
#include "xiic.h"
#include "xil_printf.h"
#include "xintc.h"
#ifdef XPAR_INTC_0_DEVICE_ID
#define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
#define IIC_INTR_ID XPAR_INTC_0_IIC_0_VEC_ID
#define INTC XIntc
#define INTC_HANDLER XIntc_InterruptHandler
#else
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#define IIC_INTR_ID XPAR_FABRIC_IIC_0_VEC_ID
#define INTC XScuGic
#define INTC_HANDLER XScuGic_InterruptHandler
#endif
XIic IicInstance; /* The instance of the IIC device. */
INTC Intc; /* The instance of the Interrupt Controller Driver */
volatile u8 TransmitComplete; /* Flag to check completion of Transmission */
volatile u8 ReceiveComplete; /* Flag to check completion of Reception */
static void SendHandler(XIic *InstancePtr)
{
TransmitComplete = 0;
xil_printf("iic sending data... \n\r");
}
static void ReceiveHandler(XIic *InstancePtr)
{
ReceiveComplete = 0;
xil_printf("iic receiving data... \n\r");
}
static void StatusHandler(XIic *InstancePtr, int Event)
{
}
int IicSelfTestExample(u16 DeviceId);
static int SetupInterruptSystem(XIic *IicInstPtr)
{
XIntc_Initialize(&Intc, INTC_DEVICE_ID);
XIntc_Connect(&Intc, IIC_INTR_ID,(XInterruptHandler) XIic_InterruptHandler,IicInstPtr);
XIntc_Start(&Intc, XIN_REAL_MODE);
XIntc_Enable(&Intc, IIC_INTR_ID);
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)INTC_HANDLER, &Intc);
Xil_ExceptionEnable();
return XST_SUCCESS;
}
int IicSelfTestExample(u16 DeviceId)
{
int Status;
XIic_Config *ConfigPtr; /* Pointer to configuration data */
ConfigPtr = XIic_LookupConfig(DeviceId);
XIic_CfgInitialize(&IicInstance, ConfigPtr, ConfigPtr->BaseAddress);
SetupInterruptSystem(&IicInstance);
// Set the Handlers for transmit and reception.
XIic_SetSendHandler(&IicInstance, &IicInstance,
(XIic_Handler) SendHandler);
XIic_SetRecvHandler(&IicInstance, &IicInstance,
(XIic_Handler) ReceiveHandler);
XIic_SetStatusHandler(&IicInstance, &IicInstance,
(XIic_StatusHandler) StatusHandler);
// Set the address of the slave.
XIic_SetAddress(&IicInstance, XII_ADDR_TO_SEND_TYPE, 0x74);
//Write to the PCA9548.
TransmitComplete = 1;
IicInstance.Stats.TxErrors = 0;
u8 select = 1;
Status = XIic_Start(&IicInstance);
Status |= XIic_MasterSend(&IicInstance, &select, 1);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
while ((TransmitComplete) || (XIic_IsIicBusy(&IicInstance) == TRUE)) {} // wait
// read back for test
ReceiveComplete = 1;
u8 back;
Status = XIic_Start(&IicInstance);
Status |= XIic_MasterRecv(&IicInstance, &back, 1);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
while ((ReceiveComplete) || (XIic_IsIicBusy(&IicInstance) == TRUE)) {} // wait
if (back == select)
xil_printf("IIC device select initial success!\n\r");
else
xil_printf("IIC device select initial failed!\n\r");
return XST_SUCCESS;
}
经过初步测试,可以成功往0x74地址里面写值,接下来就是具体到FMC接口的配置了。
上一篇: Java编程实现递增排序链表的合并