I am struggling at the moment to integrate some 3rd party code into a project I’m working on. The 3rd parties code is written in C and my main code is CPP. I’m struggling with the pointer references and I’ve still a lot to learn regarding this.
I am running the code on a Teensy 3.5 board and linking up to the 3rd party’s product via SPI. I’m using Platform IO within Visual Studio Code.
In the 3rd party code they have packaged all the data up for me and it should be a simple case of just clocking the bytes in & out over the SPI bus. The area I’m struggling with is they are using void pointers to the Tx & Rx data blocks. I’m also not sure where or how to write the received data back to the pointer.
I've attached some code below at my initial attempts but welcome any assistance anyone could offer.
Main.cpp
3rd Party's C
I am running the code on a Teensy 3.5 board and linking up to the 3rd party’s product via SPI. I’m using Platform IO within Visual Studio Code.
In the 3rd party code they have packaged all the data up for me and it should be a simple case of just clocking the bytes in & out over the SPI bus. The area I’m struggling with is they are using void pointers to the Tx & Rx data blocks. I’m also not sure where or how to write the received data back to the pointer.
I've attached some code below at my initial attempts but welcome any assistance anyone could offer.
Main.cpp
HTML:
SPISettings SPIconfig(1000000, MSBFIRST, SPI_MODE0);
extern "C" void TNSY_SPI_TransmitReceive(uint8_t *dataTx, uint8_t *dataRx, uint16_t len) {
Serial.print("TNSY_SPI_TransmitReceive: ");
SPI.beginTransaction(SPIconfig);
digitalWrite(SLAVESELECT,LOW);
delayMicroseconds(1);
for (uint16_t i = 0; i < len; i++) {
*dataRx = SPI.transfer(*dataTx); // send the data, while storing the received data
dataTx++; // increment the pointer to the next value
dataRx++; // increment the poitner to the next space for RXdata
}
digitalWrite(SLAVESELECT,HIGH);
delayMicroseconds(1);
SPI.endTransaction();
}
3rd Party's C
HTML:
static SpiDataReceivedCbfType pnDataReadyCbf;
void SpiRegDataReceived(SpiDataReceivedCbfType pnDataReceived )
{
pnDataReadyCbf = pnDataReceived;
}
void SpiSendReceive( void* pxSendDataBuffer, void* pxReceiveDataBuffer, UINT16 iLength )
{
TNSY_SPI_TransmitReceive(pxSendDataBuffer, pxReceiveDataBuffer, iLength);
pnDataReadyCbf();
}