Zynq7000 I2C don't work, but register are set properly

1

I'm trying to write piece of code, to send data via I2C on my Zynq7020 device. There are 11 register asociated with I2C and I'm prety sure, that I have set this properly. I also double check registers asociated with CPU_1X clock enable a and I2C reset, but they are set properly by default. When I set all data by the code bellow, status register is 0x00000040 and interupt status register is 0x00000000 all the time. I think, there must be some enable register, but I can't find anything in datasheet. Thanks for all replies.

//I2C registers 
#define XIICPS_CR           0xE0004000 //Controll register
#define XIICPS_SR           0xE0004004 //Status register
#define XIICPS_ADDR         0xE0004008 //IIC Address register
#define XIICPS_DATA         0xE000400C //IIC data register
#define XIICPS_ISR          0xE0004010 //IIC interrupt status register
#define XIICPS_TRANS_SIZE   0xE0004014 //Transfer Size Register
#define XIICPS_SLV_PAUSE    0xE0004018 //Slave Monitor Pause Register
#define XIICPS_TIME_OUT     0xE000401C //Time out register
#define XIICPS_IMR          0xE0004020 //Interrupt mask register
#define XIICPS_IER          0xE0004024 //Interrupt Enable Register
#define XIICPS_IDR          0xE0004028 //Interrupt Disable Register

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"


int main()
{
    init_platform();
    initI2C();

    while(1){
        printf("Write start\n\r");
        writeI2C(0x6C, 0x00);       //I have device with 0x6C adress connected;
        printf("Write done\n\r");
    }

    cleanup_platform();
    return 0;
}

void initI2C(){
    *((unsigned int*)XIICPS_CR) = 0x0000905E;   //((15:14)CLK_A = 2, (13:8)CLK_B = 16, (6)CLR_FIFO=1, (5)MONITOR_MODE=0, (4)HOLD=1, (3)1, (2)1, (1)MASTER=1, (0)rv = 0)
    *((unsigned int*)XIICPS_TIME_OUT) = 0x000000FF; //set timeout to 255
    *((unsigned int*)XIICPS_IER) = 0x00000000;  //no interupts (I'm pretty sure, that this line can't do anything, but it's in datasheet...)
    *((unsigned int*)XIICPS_IDR) = 0x000002FF;  //no interupts
    return;
}

void writeI2C(unsigned addr, unsigned data){
    *((unsigned int*)XIICPS_CR) = (*((unsigned int*)XIICPS_CR)|0x00000040)&0xFFFFFFFE; //CLR_FIFO and WRITE_MODE
    
    *((unsigned int*)XIICPS_DATA) = data;   //When I debug this with JTAG, I can see XIICPS_TRANS_SIZE increment by this lines. So data goes into FIFO properly, right?
    *((unsigned int*)XIICPS_DATA) = data;
    *((unsigned int*)XIICPS_DATA) = data;
    *((unsigned int*)XIICPS_DATA) = data;

    *((unsigned int*)XIICPS_ADDR) = addr;

    while(*((unsigned int*)XIICPS_SR) != 0){    //this loop will never exit. Data sits in FIFO forever. No errors in status or interupt status registers, everything looks fine.
            print("Wait1...\n\r");
        }

    while(*((unsigned int*)XIICPS_ISR)&0x00000001 == 0){
        print("Wait2...\n\r");
    }
    return;
    
}
c
i2c
zynq
asked on Stack Overflow Jun 30, 2020 by Thugmek

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0