cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gbisson
Visitor
Visitor
435 Views
Registered: ‎04-13-2021

Problem with reading I2C register bank

Jump to solution

Hello,

I'm using a zynq ultrascle plus module (mars XU3) connected to a board (mars EB1). I need to access the I2C register back to read and write some registers in order to change the functionality of the system controller, situated on the mars EB1 board.

The I2C register bank is situated at the bus address 0x0D. In the board manual it is present this diagram on how to read and write the data (I think the 0001101 in the diagram corresponds to the address 0x0D): diagramI2C.png

I'm using vitis to read and write these registers.

I wrote some c code based on this xilinx examples for the iicps driver. After these initial operations:

 

XIicPs_Config *Config;
	int Status;

	/*
	 * Initialize the IIC driver so that it's ready to use
	 * Look up the configuration in the config table, then initialize it.
	 */
	Config = XIicPs_LookupConfig(IIC_DEVICE_ID);
	if (NULL == Config) {
		return XST_FAILURE;
	}

	Status = XIicPs_CfgInitialize(&Iic, Config, Config->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */
	Status = XIicPs_SelfTest(&Iic);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	/*
	 * Connect the IIC to the interrupt subsystem such that interrupts can
	 * occur. This function is application specific.
	 */
	Status = SetupInterruptSystem(&Iic);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	/*
	 * Setup the handlers for the IIC that will be called from the
	 * interrupt context when data has been sent and received, specify a
	 * pointer to the IIC driver instance as the callback reference so
	 * the handlers are able to access the instance data.
	 */
	XIicPs_SetStatusHandler(&Iic, (void *) &Iic, Handler);

	/*
	 * Set the IIC serial clock rate.
	 */
	XIicPs_SetSClk(&Iic, IIC_SCLK_RATE);

 

I use this code to read the registers:

 

/*
	 * Wait bus activities to finish.
	 */
	while (XIicPs_BusIsBusy(&Iic)) {
		/* NOP */
	}

	/*
	 * Receive data from slave, errors are reported through
	 * TotalErrorCount.
	 */
	RecvComplete = FALSE;
	XIicPs_MasterRecv(&Iic, RecvBuffer, RECV_BUFFER_SIZE,
			IIC_SLAVE_ADDR);
	
	while (!RecvComplete) {
		if (0 != TotalErrorCount) {
			return XST_FAILURE;
		}
	}

 

 where IIC_SLAVE_ADDR = 0x0D (the address of the iic register bank on the bus).

The problem here is that every time that I execute the reading process from the code the address I read from increments by one. if I change IIC_SLAVE_ADDR to a specific address I can't read at all.

I don't know what I need the change in the code the respect the diagram above. Where should I put the "Address" form the diagram above in order to read that specific address?

 

Thanks in advance,

Giacomo

0 Kudos
1 Solution

Accepted Solutions
drjohnsmith
Teacher
Teacher
417 Views
Registered: ‎07-09-2009

You need to look at the data sheet of the device your talking to,

 

In I2C, a device typically sits at one address out of the 127 I2C address available,

    Most I2C devices would need an address / data format to read from one register in the particular device.

      The address is the I2C address of the device , with the read / write bit,

             then normally would be an address of where in the device you want to to read from,

Most I2C devices have the ability to do a read / address format, and a address only, 

    So you can do say a read of device at address A0, register 10,  

       then do multiple reads of address A0, and the device will increment the internal register read, thus saving time on the I2C bus to read a bunch of data ,

Its all going to be in the  data sheet of the device you want to read from, refer to tat data sheet,

 

https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/

 

<== If this was helpful, please feel free to give Kudos, and close if it answers your question ==>

View solution in original post

1 Reply
drjohnsmith
Teacher
Teacher
418 Views
Registered: ‎07-09-2009

You need to look at the data sheet of the device your talking to,

 

In I2C, a device typically sits at one address out of the 127 I2C address available,

    Most I2C devices would need an address / data format to read from one register in the particular device.

      The address is the I2C address of the device , with the read / write bit,

             then normally would be an address of where in the device you want to to read from,

Most I2C devices have the ability to do a read / address format, and a address only, 

    So you can do say a read of device at address A0, register 10,  

       then do multiple reads of address A0, and the device will increment the internal register read, thus saving time on the I2C bus to read a bunch of data ,

Its all going to be in the  data sheet of the device you want to read from, refer to tat data sheet,

 

https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/

 

<== If this was helpful, please feel free to give Kudos, and close if it answers your question ==>

View solution in original post