aminbahrami
Junior Member level 3
Hi all
I am working with spartan 3a dsp 3400 board.
I create a new design with microblaze for my board.
I now want to write a simple code for IIC.
I used the following function for writing data to a register of a chip using iic.
/******************************************************************************
* This function writes a buffer of bytes to the IIC chip.
*
* @param CoreAddress contains the address of the IIC core.
* @param ChipAddress contains the address of the chip.
* @param RegAddress contains the address of the register to write to.
* @param BufferPtr contains the address of the data to write.
* @param ByteCount contains the number of bytes in the buffer to be written.
* Note that this should not exceed the page size as noted by the
* constant PAGE_SIZE.
*
* @return The number of bytes written, a value less than that which was
* specified as an input indicates an error.
*
* @note None.
*
******************************************************************************/
Xuint8 vsk_iic_write(Xuint32 IICCoreAddress, Xuint8 ChipAddress, Xuint8 RegAddress,
Xuint8 *BufferPtr, Xuint8 ByteCount)
{
Xuint8 SentByteCount;
Xuint8 WriteBuffer[IIC_PAGE_SIZE + 1];
Xuint8 Index;
Xuint8 StatusReg;
// Make sure all the Fifo's are cleared and Bus is Not busy.
do
{
StatusReg = XIo_In8(CoreAddress + XIIC_SR_REG_OFFSET);
StatusReg = StatusReg & (XIIC_SR_RX_FIFO_EMPTY_MASK |
XIIC_SR_TX_FIFO_EMPTY_MASK |
XIIC_SR_BUS_BUSY_MASK);
} while (StatusReg != (XIIC_SR_RX_FIFO_EMPTY_MASK |
XIIC_SR_TX_FIFO_EMPTY_MASK)); /*
* A temporary write buffer must be used which contains both the address
* and the data to be written, put the address in first
*/
WriteBuffer[0] = RegAddress;
/*
* Put the data in the write buffer following the address.
*/
for (Index = 0; Index < ByteCount; Index++)
{
WriteBuffer[Index + 1] = BufferPtr[Index];
}
/*
* Write data at the specified address.
*/
SentByteCount = XIic_DynSend(CoreAddress, ChipAddress, WriteBuffer,
ByteCount + 1, XIIC_STOP);
if (SentByteCount < 1) { SentByteCount = 1; }
// Return the number of bytes written.
return SentByteCount - 1;
}
But my function remains in the while loop (which is seperated with another color.)
I used a xil_printf function after line: StatusReg = XIo_In8(CoreAddress + XIIC_SR_REG_OFFSET);
to display the value of statusreg variable
but i only see statusreg=0 and function remains in do_while loop
in the next step I read the value of other registers with XIo_In8 , but it returns 0 to other registers too.
then I write 0x07 in a specific register using Xio_out8 function and i read the same register using XIo_In8 but the read value was 0!!!!!!!!!!!!!!!!!!
The above code is xilinx code for iic of my board.
can any one help me what i must do with this unction or tell me the reason of this subject?
can any one give me another code for i2c if he/she has another code for iic please
thanx
I am working with spartan 3a dsp 3400 board.
I create a new design with microblaze for my board.
I now want to write a simple code for IIC.
I used the following function for writing data to a register of a chip using iic.
/******************************************************************************
* This function writes a buffer of bytes to the IIC chip.
*
* @param CoreAddress contains the address of the IIC core.
* @param ChipAddress contains the address of the chip.
* @param RegAddress contains the address of the register to write to.
* @param BufferPtr contains the address of the data to write.
* @param ByteCount contains the number of bytes in the buffer to be written.
* Note that this should not exceed the page size as noted by the
* constant PAGE_SIZE.
*
* @return The number of bytes written, a value less than that which was
* specified as an input indicates an error.
*
* @note None.
*
******************************************************************************/
Xuint8 vsk_iic_write(Xuint32 IICCoreAddress, Xuint8 ChipAddress, Xuint8 RegAddress,
Xuint8 *BufferPtr, Xuint8 ByteCount)
{
Xuint8 SentByteCount;
Xuint8 WriteBuffer[IIC_PAGE_SIZE + 1];
Xuint8 Index;
Xuint8 StatusReg;
// Make sure all the Fifo's are cleared and Bus is Not busy.
do
{
StatusReg = XIo_In8(CoreAddress + XIIC_SR_REG_OFFSET);
StatusReg = StatusReg & (XIIC_SR_RX_FIFO_EMPTY_MASK |
XIIC_SR_TX_FIFO_EMPTY_MASK |
XIIC_SR_BUS_BUSY_MASK);
} while (StatusReg != (XIIC_SR_RX_FIFO_EMPTY_MASK |
XIIC_SR_TX_FIFO_EMPTY_MASK)); /*
* A temporary write buffer must be used which contains both the address
* and the data to be written, put the address in first
*/
WriteBuffer[0] = RegAddress;
/*
* Put the data in the write buffer following the address.
*/
for (Index = 0; Index < ByteCount; Index++)
{
WriteBuffer[Index + 1] = BufferPtr[Index];
}
/*
* Write data at the specified address.
*/
SentByteCount = XIic_DynSend(CoreAddress, ChipAddress, WriteBuffer,
ByteCount + 1, XIIC_STOP);
if (SentByteCount < 1) { SentByteCount = 1; }
// Return the number of bytes written.
return SentByteCount - 1;
}
But my function remains in the while loop (which is seperated with another color.)
I used a xil_printf function after line: StatusReg = XIo_In8(CoreAddress + XIIC_SR_REG_OFFSET);
to display the value of statusreg variable
but i only see statusreg=0 and function remains in do_while loop
in the next step I read the value of other registers with XIo_In8 , but it returns 0 to other registers too.
then I write 0x07 in a specific register using Xio_out8 function and i read the same register using XIo_In8 but the read value was 0!!!!!!!!!!!!!!!!!!
The above code is xilinx code for iic of my board.
can any one help me what i must do with this unction or tell me the reason of this subject?
can any one give me another code for i2c if he/she has another code for iic please
thanx