From a1822c595fdf041a5bcbf4bdfb79b194b01a0989 Mon Sep 17 00:00:00 2001 From: Werner Johansson Date: Sun, 21 Dec 2014 09:18:37 -0800 Subject: [PATCH] Bugfix SPI_TC_Init numspidevices handling An incorrect assumption was made that SPI_TC_Work could be used during init (before numspidevices was properly initialized). numspidevices variable is now properly initialized before attemting to probe (and still kept at zero until init is run). Thanks to patrickwtlaw for tracking this thing down! --- src/max31855.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/max31855.c b/src/max31855.c index 58a38ff..3f6cefe 100644 --- a/src/max31855.c +++ b/src/max31855.c @@ -48,7 +48,6 @@ static int32_t SPI_TC_Work( void ) { } uint32_t SPI_TC_Init( void ) { - uint32_t numspidevices = 0; printf("\n%s called",__FUNCTION__); Sched_SetWorkfunc( SPI_TC_WORK, SPI_TC_Work ); @@ -60,7 +59,9 @@ uint32_t SPI_TC_Init( void ) { if( SC18IS602B_Init( SPICLK_1843KHZ, SPIMODE_0, SPIORDER_MSBFIRST ) >= 0 ) { // Only continue of we find the I2C to SPI bridge chip printf("\nProbing for MAX31855 devices..."); + numspidevices = MAX_SPI_DEVICES; // Assume all devices are present for SPI_TC_Work SPI_TC_Work(); // Run one iteration to update all data + numspidevices = 0; // And reset it afterwards for( int i = 0; i < MAX_SPI_DEVICES; i++ ) { if( (spidevreadout[i] == -1 && spiextrareadout[i] == -1) ||