I am attempting to convert some software written for the DWM3000 to arduino
and am getting a little lost in the program and the necessary SPI commands to talk to the unit.
This is a stripped down call sequence in the program I am converting.
First Question
The links between the subroutines using pointers to return data.
dwt_read32bitoffsetreg sets uint8_t buffer[4];
dwt_readfromdevice links this as uint8_t *buffer (a pointer)
dwt_xfer3000 also links this as uint8_t *buffer (a pointer)
readfromspi links this as uint8_t *readBuffer (a pointer)
Can someone please explain this, as the readbuffer has to eventually end up as 4 bytes in buffer
Second question
dwt_xfer3000 sets uint8_t header[2];
readfromspi links this as uint8_t *headerBuffer (a pointer)
Does this command send both header bytes?
SPI.transfer((uint8_t *)headerBuffer); // Send header
Third question
How to I get the results from an SPI read into buffer, back through the pointer system
Any assistance gratefully received. This software is doing my head in
uint32_t dwt_readdevid(void)
{
return dwt_read32bitoffsetreg(DEV_ID_ID,0)
}
uint32_t dwt_read32bitoffsetreg (int regFileID, int regOffset)
{
uint8_t buffer[4];
dwt_readfromdevice(regFileID,regOffset,4,buffer); // Read 4 bytes (32-bits) register into buffer
}
void dwt_readfromdevice (uint32_t regFileID, uint16_t index, uint16_t lengthA, uint8_t *buffer)
{
dwt_xfer3000(regFileID, index, lengthA, buffer, DW3000_SPI_RD_BIT);
}
void dwt_xfer3000 (const uint32_t regFileID,const uint16_t indx,const uint16_t lengthA, uint8_t *buffer, const spi_modes_e mode)
{
uint8_t header[2]; // Buffer to compose header in
uint16_t cnt = 0; // Counter for length of a header
////cnt and header populated
readfromspi(cnt, header, lengthA, buffer);
}
int readfromspi(uint16_t headerLength,uint8_t *headerBuffer,uint16_t readlength,uint8_t *readBuffer)
{
SPI.transfer((uint8_t *)headerBuffer); // Send header
// how do I get the read from SPI
return 0;
}