usingQuestion refactored:
Im currently struggling to understand how to update the transmit FIFO of the bsc_xfer.
For reference:
Slave side:
int main(int argc, char** argv)
{
int GPIO = gpioInitialise();
if(GPIO)
{
bsc_xfer_t xfer;
xfer.control = (0x09<<16) | 0x305;
int status = bscXfer(&xfer);
TL;DR: is there a proper way to manage register reads as an I2C slave using bscXfer?
Assuming that I received two bytes: 0xA1 followed by 0x01, those bytes are requesting my Pi (slave) to send an arbitrary buffer, 0xA1 followed by 0x02 ask for another buffer.
My current way to handle that is a switch case, that set : xfer.txBuf, xfer.txCnt, then update the xfer.control to allow sending data, loop until the status (bscXfer(&xfer)) isn't Transmit Busy anymore, then reset the control to block sender(to avoid sending the wrong buffer).
And as the library is really extensive, I'm convinced that those callback event must be defined.
int eventSetFunc std::cout<<"\nstatus: "<<status<<std::endl;
if(unsignedstatus event>= 0)
{
while(1)
{
status = bscXfer(&xfer);
if (status)
{
if(xfer.rxCnt > 0)
{
printf("\nRxCnt: %d RxVal: %x\n", eventFunc_txfer.rxCnt, fxfer.rxBuf[0]);
seems to be what I need, but I'm missing the way to link it to the xfer, and handlers for I2C seems to be master only.
is there an easier way to handle request event as an I2C slave with pigpio?
see below code
switch(REQ_REGISTERxfer.rxBuf[0])
{
case WHO_I_AM0x00:
memcpy(xfer.txBuf, "DSV_""ABCD", 4);
xfer.txCnt = 4;
break;
case 0x01:
memcpy(xfer.txBuf, "FGHI", 4);
xfer.controltxCnt = Ctrl_sender_allowed;4;
// break;
default:
break;
}
memset(Address<<16 xfer.rxBuf, '\0', BSC_FIFO_SIZE );
| 0x305
waitTransfer }
}
}
}
}
}
Master side:
int main(xferint argc, char** argv)
{
int GPIO = gpioInitialise();
if(GPIO)
{
int handler = i2cOpen(1, 9, 0);
// def as
std:while:cout<<"\nHandler: "<<handler<<std::endl;
if(bscXferhandler >= 0)
{
int wr = i2cWriteByte(&xferhandler, 0x00);
&
std::cout<<"\nwr: "<<wr<<std::endl;
if(1<<0wr >= 0)
{
char buf[5] = "1111";
int test = i2cReadDevice(handler, buf, 4);
std::cout<<"\ntest: "<<test<<std::endl;
if(test >= 0)
{
std::cout<<"\nReceived: " << buf;
}
xfer.control
std::cout<<std::endl;
wr = Ctrl_sender_disabledi2cWriteByte(handler, |0x01);
0x205;//
std::cout<<"\nwr(Address<<162): |"<<wr<<std::endl;
0x205
if(wr >= 0)
{
test = i2cReadDevice(handler, buf, 4);
break;
[...] std::cout<<"\ntest(2): "<<test<<std::endl;
if(test >= 0)
{
std::cout<<"\nReceived: "<<buf;
}
std::cout<<std::endl;
}
}
}
}
else
{
std::cout<<"\nGPIO init error"<<std::endl;
}
return 0;
}
expected output:
Received: ABCD
Received: FGHI
actual output:
Received: ABCD
Received: AFGH
Question: I'm missing how to reset the Tx fifo correctly, is there a proper way or am I touching something not covered by the lib?