- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have created an i2c project like the given example but I see a delay on the read buffer thats returned to the master. Its returns the correct buffer on subsequent requests. For example using the bridge control gui. I send a start with a write address and a sub command... then send a repeated start with a read and returns blank on the first command. It appears from the datasheet that the function I2C_SlaveInitReadBuf has a side effect of "If this function is called during a bus transaction, data from the previous buffer location and the beginning of the current buffer may be transmitted." This seems exactly what I am doing with a repeated start.
s 10 0A s 11 x x p
The first time run it returns
s 10+ 0A+ s 11+ 00+ 00+ p
then any following command reads
s 10+ 0A+ s 11+ 00+ 04+ p
Do I need to run a command after I set the return buffer variable?
#include <project.h>
#include <stdio.h>
#include <header01.h>
/* I2C slave read and write buffers */
uint8 i2cReadBuffer[7];
uint8 i2cWriteBuffer[7];
uint16 i2cbuffer;
int main()
{
CyGlobalIntEnable; /* Enable global interrupts. */
CyWdtStart(CYWDT_1024_TICKS,CYWDT_LPMODE_NOCHANGE);
/* Start I2C slave (SCB mode) */
I2C_1_Start();
I2C_1_SlaveInitReadBuf(i2cReadBuffer, 7);
I2C_1_SlaveInitWriteBuf(i2cWriteBuffer, 7);
int32 temperature = 0;
for(;;)
{
CyWdtClear();
/* Write complete: parse command packet */
if (0u != (I2C_1_SlaveStatus() & I2C_1_SSTAT_WR_CMPLT))
{
ExecuteWriteCommand(i2cWriteBuffer[0], i2cWriteBuffer);
/* Clear slave write buffer and status */
I2C_1_SlaveClearWriteBuf();
(void) I2C_1_SlaveClearWriteStatus();
}
/* Read complete: expose buffer to master */
if (0u != (I2C_1_SlaveStatus() & I2C_1_SSTAT_RD_CMPLT))
{
/* Clear slave read buffer and status */
I2C_1_SlaveClearReadBuf();
(void) I2C_1_SlaveClearReadStatus();
}
}
}
/*******************************************************************************
* ExecuteCommand(): executes received command and returns status
*******************************************************************************/
void ExecuteWriteCommand(uint32 cmd, uint8_t *buffer)
{
int16 return_value;
/* Execute received command */
switch (cmd)
{
case 0x0A:
return_value = 4;
i2cReadBuffer[0] = (return_value & 0xFF00) >> 8 ;
i2cReadBuffer[1] = (return_value & 0x00FF);
default:
break;
}
}
/* [] END OF FILE */
- Labels:
-
PSoC 5LP
- Tags:
- i2c
- troubleshoot i2c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please provide us with your project