- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Reading from raspberry pi via I2C - how can I reset the read pointer to the first byte of the read buffer by my raspberry? I am using python on the raspberry.
Solved! Go to Solution.
- Labels:
-
PSoC 4 Architecture
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi UlMo_4589691,
Thank you for sharing your code.
There were a few issues that I found in your code.
>CapSense_ScanAllWidgets();
This function is not a polling function. So, execution continues even though the scan is not completed. The next step processes the widgets though the scan is not completed. You can refer to any CapSense code example for more information.
I also changed the I2C status check conditions according to the code examples.
So please change your code to -
/****************************************************************************************
* After CapSense_Start();
uint32 centroid;
for(;1;)
{
if(0u == CapSense_IsBusy())
{
CapSense_ProcessAllWidgets();
/*Get the touch position(centroid) of CapSense Linear Slider*/
centroid = CapSense_GetCentroidPos(CapSense_SLD_WDGT_ID);
int LED9wert=CapSense_IsWidgetActive(CapSense_BTN0_WDGT_ID);
int LED10wert=CapSense_IsWidgetActive(CapSense_BTN1_WDGT_ID);
int LED11wert=CapSense_IsWidgetActive(CapSense_BTN2_WDGT_ID);
/*Turn ON/OFF LEDs based on the status of the corresponding CapSense buttons*/
LED9_Write(LED9wert ? LED_ON : LED_OFF );
LED10_Write(LED10wert ? LED_ON : LED_OFF );
LED11_Write(LED11wert ? LED_ON : LED_OFF );
/*Turn ON/OFF LEDs based on the finger position (centroid) on the CapSense Linear slider*/
if(CapSense_IsWidgetActive(CapSense_SLD_WDGT_ID))
{
LED4_Write( ( (centroid > 0) || (centroid == 0)) ? LED_ON : LED_OFF );
LED5_Write( ( centroid > ( 1 * STEP_SIZE ) ) ? LED_ON : LED_OFF);
LED6_Write( ( centroid > ( 2 * STEP_SIZE ) ) ? LED_ON : LED_OFF);
LED7_Write( ( centroid > ( 3 * STEP_SIZE ) ) ? LED_ON : LED_OFF);
LED8_Write( ( centroid > ( 4 * STEP_SIZE ) ) ? LED_ON : LED_OFF);
}
else
{
LED4_Write(LED_OFF);
LED5_Write(LED_OFF);
LED6_Write(LED_OFF);
LED7_Write(LED_OFF);
LED8_Write(LED_OFF);
}
CapSense_ScanAllWidgets();
}
//Nachricht an Master ----------------------------------------------------------------------------------------------------------
if(0u != (I2CS_I2CSlaveStatus() & I2CS_I2C_SSTAT_RD_CMPLT))
{
I2C_1_I2CSlaveClearReadStatus();
I2C_1_I2CSlaveClearReadBuf();
readBuffer[0]=centroid;
readBuffer[1]=LED9wert;
readBuffer[2]=LED10wert;
readBuffer[3]=LED11wert;
}
//Nachricht von Master
if(0u != (I2CS_I2CSlaveStatus() & I2CS_I2C_SSTAT_WR_CMPLT))
{
byteCnt=I2C_1_I2CSlaveGetWriteBufSize();
for (uint8 i=0; i<byteCnt;i++)
{
userArray=writeBuffer;
}
I2C_1_I2CSlaveClearWriteStatus();
I2C_1_I2CSlaveClearWriteBuf();
}
}
Please check if this code works for you. If not please attach both the PSoC Project and the RPi code so that it will be easier for us to debug.
Thanks and Regards,
Rakshith M B
Rakshith M B