Skip to main content
Post Closed as "Not suitable for this site" by goldilocks
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Commonmark migration
Source Link

Received: ABCD

 

Received: FGHI

Received: ABCD

 

Received: AFGH

Received: ABCD

 

Received: FGHI

Received: ABCD

 

Received: AFGH

Received: ABCD

Received: FGHI

Received: ABCD

Received: AFGH

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
changed everything
Source Link
Ebya
  • 113
  • 1
  • 5

piGPIO properly handle request event in c++ as slave pigpio, update xfer.txBuf

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?

piGPIO properly handle request event in c++ as slave

using:

 bsc_xfer_t xfer;
 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(unsigned event, eventFunc_t f);

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_REGISTER)
 {
      case WHO_I_AM:
      memcpy(xfer.txBuf, "DSV_", 4);
      xfer.txCnt = 4;
                                        
      xfer.control = Ctrl_sender_allowed; //(Address<<16) | 0x305
      waitTransfer(xfer)(); // def as :while(bscXfer(&xfer) &(1<<0)){}
      xfer.control = Ctrl_sender_disabled | 0x205;//(Address<<16) | 0x205
                                        
      break;
[...]
}

pigpio, update xfer.txBuf

Question 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);
    std::cout<<"\nstatus: "<<status<<std::endl;
    
    if(status >= 0)
    {
        while(1)
        {
            status = bscXfer(&xfer);
            if (status)
            {
                if(xfer.rxCnt > 0)
                {
                    
                    printf("\nRxCnt: %d RxVal: %x\n", xfer.rxCnt, xfer.rxBuf[0]);
                    switch(xfer.rxBuf[0])
                    {
                        case 0x00:
                        memcpy(xfer.txBuf, "ABCD", 4);
                        xfer.txCnt = 4;
                        break;
                        
                        case 0x01:
                        memcpy(xfer.txBuf, "FGHI", 4);
                        xfer.txCnt = 4;
                        break;
                        
                        default:
                        break;
                    }
                    memset( xfer.rxBuf, '\0', BSC_FIFO_SIZE );
                    
                }
            }
        }
    }
    
}
}

Master side:


int main(int argc, char** argv)
{
int GPIO = gpioInitialise();

if(GPIO)
{
    int handler = i2cOpen(1, 9, 0); 
    
    std::cout<<"\nHandler: "<<handler<<std::endl;
    
    if(handler >= 0)
    {
        int wr = i2cWriteByte(handler, 0x00);
        
        std::cout<<"\nwr: "<<wr<<std::endl;
        
        if(wr >= 0)
        {
            char buf[5] = "1111";
           
            int test = i2cReadDevice(handler, buf, 4);
            
            std::cout<<"\ntest: "<<test<<std::endl;
            
            if(test >= 0)
            {
                std::cout<<"\nReceived: " << buf;
            }
            
            std::cout<<std::endl;
            
            wr = i2cWriteByte(handler, 0x01);
        
            std::cout<<"\nwr(2): "<<wr<<std::endl;
        
            if(wr >= 0)
            {
                test = i2cReadDevice(handler, buf, 4);
            
                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?

added code
Source Link
Ebya
  • 113
  • 1
  • 5

using:

 bsc_xfer_t xfer;
 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(unsigned event, eventFunc_t f);

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_REGISTER)
 {
      case WHO_I_AM:
      memcpy(xfer.txBuf, "DSV_", 4);
      xfer.txCnt = 4;
                                        
      xfer.control = Ctrl_sender_allowed; //(Address<<16) | 0x305
      waitTransfer(xfer)(); // def as :while(bscXfer(&xfer) &(1<<0)){}
      xfer.control = Ctrl_sender_disabled | 0x205;//(Address<<16) | 0x205
                                        
      break;
[...]
}

using:

 bsc_xfer_t xfer;
 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(unsigned event, eventFunc_t f);

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?

using:

 bsc_xfer_t xfer;
 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(unsigned event, eventFunc_t f);

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_REGISTER)
 {
      case WHO_I_AM:
      memcpy(xfer.txBuf, "DSV_", 4);
      xfer.txCnt = 4;
                                        
      xfer.control = Ctrl_sender_allowed; //(Address<<16) | 0x305
      waitTransfer(xfer)(); // def as :while(bscXfer(&xfer) &(1<<0)){}
      xfer.control = Ctrl_sender_disabled | 0x205;//(Address<<16) | 0x205
                                        
      break;
[...]
}
Source Link
Ebya
  • 113
  • 1
  • 5
Loading