UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor mgago2013
Visitor
285 Views
Registered: ‎05-16-2018

Iicps library, using ZedBoard as a master device

Hello 

 

First of all, I am a newbie so I hope I am writing this in the correct pace. 

 

I am trying to receive data using i2c from the specific register of the slave device with the 7bit address of 0x42 (0b1000010X, where X is R/W bit). As a master device I am using PS side of the ZYNQ on the ZedBoard. I decided to use iicps library from Xilinx SDK.

 

Generally, in i2c reading is done as fallows:

 

Write data first:

<I2C slave address><get ACK><register address><get ACK>

Then Read:

<I2C slave address><get ACK><received data><NACK>

blue is done by master and red by slave. 

 

This is my script: 

 

 

#include <stdio.h>
#include "platform.h"
#include "xparameters.h"
#include "xiicps.h"

#define IIC_DEVICE_ID		XPAR_XIICPS_0_DEVICE_ID

#define IIC_SLAVE_ADDR		(0x84>>1)


#define IIC_SCLK_RATE		100000

#define TEST_BUFFER_SIZE	10




XIicPs Iic;		/* Instance of the IIC Device */


u8 SendBuffer[TEST_BUFFER_SIZE];    
u8 RecvBuffer[TEST_BUFFER_SIZE];    


int main()
{

	XIicPs_Config *Config;

	Config = XIicPs_LookupConfig(IIC_DEVICE_ID);

	XIicPs_CfgInitialize(&Iic, Config, Config->BaseAddress);

	XIicPs_SetSClk(&Iic, IIC_SCLK_RATE);

	SendBuffer[0] = 0x01;


	XIicPs_MasterSend(&Iic, SendBuffer, 1, IIC_SLAVE_ADDR); /*sending slave and register addresses*/


        int t = 0;
	while(t<16002)
	{
		t++;
	}

	XIicPs_MasterRecv(&Iic, RecvBuffer, 1, IIC_SLAVE_ADDR); /*sending slave address once again and receiving data*/

	printf("%d\n",RecvBuffer[0]);

	return 0;

}

This script kind of work. Here are some pictures from oscilloscope which look fine. I also checked sent and received data with the USB Logic Analyzer and everything seams to be correct. 

1.png

 

However there are two problems which I can not solve. 

1) If I decrease or erase delay (while function. delay length 6us) between send and receive function, receive function is not executed. Is this normal?  I thought that delay was not needed at all. 

 

2) even thought slave returns correct data, XIicPs_MasterRecv function is not storing it inside of RecvBuffer and printf("%d\n",RecvBuffer[0]); always returns 0. 

 

I am not very experienced in programming, so there is a high possibility that I am not using or understanding  iicps library correctly. This is why I am posting this here.

 

Thank you to everyone who will read this. I hope I have not occupied much of your time.

 

 

 

0 Kudos