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: 
Adventurer
Adventurer
8,737 Views
Registered: ‎03-15-2011

XIIC PS Master Send polled

Hi all

 

I want to be able to communicate with an IMU, the Sparkfyn LSM9DS1 (which is a slave device at address 0x6B), accessing it from the ZyBo.

When trying to write code to set up I2C communication with it, I want to be able to send data to it with XIicPs_MasterSendPolled function. However when accessing it, it always gets into an infinite loop when it is waiting for the FIFO to be empty.

I exported the signals to some ports (3.3LVCMOS pullup, ...) But I only get a high signal and no action, although I2C configuration & selftest were succesful.

- Why is it that the FIFO isn't being emptied?

- Should I normally lower the clock for the internal (Zynq PS) to get the I2C working? And if so how? (I2C should work at 100k, right now my FCLK is at 100MHz...)

- Is there a way to verify if the slave address I'm using is the correct one, as I've read at some places that sometimes you must alter it by shifting it...

 

My files: iic.c

#include "main.h"
#include "iic.h"
#include "sleep.h"

/* ---------------------------------------------------------------------------- *
 * 									IicConfig()									*
 * ---------------------------------------------------------------------------- *
 * Initialises the IIC driver by looking up the configuration in the config
 * table and then initialising it. Also sets the IIC serial clock rate.
 * ---------------------------------------------------------------------------- */
unsigned char IicConfig(unsigned int DeviceIdPS)
{
	XIicPs_Config *Config;
	int Status;

	/* Initialise the IIC driver so that it's ready to use */

	// Look up the configuration in the config table
	Config = XIicPs_LookupConfig(DeviceIdPS);
	if(NULL == Config) {
		xil_printf("IIC lookup FAILED \r\n");
		return XST_FAILURE;
	}

	// Initialise the IIC driver configuration
	Status = XIicPs_CfgInitialize(&Iic, Config, Config->BaseAddress);
	if(Status != XST_SUCCESS) {
		xil_printf("IIC config FAILED \r\n");
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */
	Status = XIicPs_SelfTest(&Iic);
	if (Status != XST_SUCCESS) {
		xil_printf("IIC selftest FAILED \r\n");
		return XST_FAILURE;

	}
	xil_printf("IIC Passed\r\n");


	//Set the IIC serial clock rate.
	Status = XIicPs_SetSClk(&Iic, IIC_SCLK_RATE);
	if (Status != XST_SUCCESS) {
		xil_printf("IIC setClock FAILED \r\n");
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}

/* ---------------------------------------------------------------------------- *
 * 								IicWriteToReg									*
 * ---------------------------------------------------------------------------- *
 * Function to write to one of the registers from the IMU
 *
 * ---------------------------------------------------------------------------- */
void IicWriteToReg(u8 u8RegAddr, u16 u16Data) {

	unsigned char u8TxData[2];

	u8TxData[0] = u8RegAddr << 1;
	u8TxData[0] = u8TxData[0] | ((u16Data >> 8) & 0b1);

	u8TxData[1] = u16Data & 0xFF;

	XIicPs_MasterSendPolled(&Iic, u8TxData, 2, LSM9DS1_GX_ADDR);
	while(XIicPs_BusIsBusy(&Iic));
}

int startIMU()
{

	xil_printf("reset  Gyr/Acc at address 6B (SDO_GX is tied high)\n");
	u16 device_addr = LSM9DS1_GX_ADDR;
	u8 buf[] = {0x22,0x08}; //0x22 Ctrl_Reg8 ==> 0x08 should be reset
	XIicPs_MasterSendPolled(&Iic, buf, 1, device_addr);
	xil_printf("reset done\n");
	return XST_SUCCESS;
}

main.c:

#include "main.h"

/* ---------------------------------------------------------------------------- *
 * 									main()										*
 * ---------------------------------------------------------------------------- *
 * Runs all initial setup functions to initialise the audio codec and IP
 * peripherals, before calling the interactive menu system.
 * ---------------------------------------------------------------------------- */
int main(void)
{
	XStatus Status;
	xil_printf("Entering Main\r\n");
	//Configure the IIC data structure
	IicConfig(XPAR_XIICPS_0_DEVICE_ID);
	xil_printf("I2c configured\n\r");
	Status = startIMU();
	if(Status != XST_SUCCESS)
	{
		xil_printf("IMU hasn't started\n");
	}

    return 1;
}

 

Lots of thanks!

Tags (2)
0 Kudos
2 Replies
Newbie maaxchen10
Newbie
3,754 Views
Registered: ‎01-19-2017

Re: XIIC PS Master Send polled

maybe you should modify the Bytecount in XilPs_MasterSendPolled from 1 to 2 ?

 

int startIMU()
{

	xil_printf("reset  Gyr/Acc at address 6B (SDO_GX is tied high)\n");
	u16 device_addr = LSM9DS1_GX_ADDR;
	u8 buf[] = {0x22,0x08}; //0x22 Ctrl_Reg8 ==> 0x08 should be reset
	XIicPs_MasterSendPolled(&Iic, buf, 1, device_addr);
	xil_printf("reset done\n");
	return XST_SUCCESS;
} 

 I also try to connect MPU6050 to zc702 but still does not work, thank for your exsample code!

best regard :)

0 Kudos
Visitor david.600
Visitor
2,673 Views
Registered: ‎05-02-2017

Re: XIIC PS Master Send polled

Did you solve his issue?
Tags (3)
0 Kudos