-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPI read is discarding the first byte #37
Comments
@GregDuckworthRenishaw Thanks for the code. I will try it out with a "standard" SPI chip, and if all goes well will incorporate your suggestion in the next release. I have nothing planned for Telemetrix, so it may likely be a while before I get to this. |
No Problem, I will be using my patched version for a while anyway. Thanks Greg |
@GregDuckworthRenishaw |
@GregDuckworthRenishaw |
I looked into altering the code, it was fairly straightforward (I used a flag in the command whether to put the first byte into the buffer), but because of the AGPL license I have had to stop working with Telemetrix altogether. No worries on closing the issue. |
Hi,
I am using an SPI device which does not implement SPI correctly and is causing trouble as a result; a MAX31855 Thermocouple Amplifier.
The interface they use is more basic than SPI typically uses insofar as the IC does not have a concept of internal addresses. They expect you to drive the chip select (CS) line low, then clock 32 bits of data out of the device, then drive the CS line high so it can read the temperature again. The IC doesn't even have an SDI pin as it never expects any data to be input.
So the difficulty is that your library (amazing btw, I am very much enjoying it) writes the address to the SPI device first, discarding the byte of data that is sent back during the initial SPI.transfer() call, then gets 4 bytes of data as it should.
A solution:
I have modified the Telemetrix4Arduino ino file to expect an extra command byte. The Arduino checks this byte to see if it should store the first byte and then acts accordingly.
I also had to modify telemetrix.py to allow this parameter to be passed through (I made the parameter default to False to preserve the functionality of existing code)
Updated Arduino Code
`
// read a number of bytes from the SPI device
void read_blocking_spi() {
#ifdef SPI_ENABLED
// command_buffer[0] == number of bytes to read
// command_buffer[1] == read register
// command_buffer[2] == Return initial transfer result too
// spi_report_message[0] = length of message including this element
// spi_report_message[1] = SPI_REPORT
// spi_report_message[2] = register used for the read
// spi_report_message[3] = number of bytes returned
// spi_report_message[4..] = data read
spi_report_message[1] = SPI_REPORT;
spi_report_message[2] = command_buffer[1]; // register
spi_report_message[3] = command_buffer[0]; // number of bytes read
if(command_buffer[2]){
// initial transfer data has been requested
// configure the report message
// calculate the packet length
spi_report_message[0] = command_buffer[0] + 4; // packet length
}
else{
// configure the report message
// calculate the packet length
spi_report_message[0] = command_buffer[0] + 3; // packet length
}
// configure the report message
// calculate the packet length
#endif
}
`
The Python was updated to this
`
def spi_read_blocking(self, register_selection, number_of_bytes_to_read,
call_back=None, return_all_data=False):
"""
Read the specified number of bytes from the specified SPI port and
call the callback function with the reported data.
`
Keep up the great work.
The text was updated successfully, but these errors were encountered: