# HG changeset patch # User Ethan Zonca # Date 2014-08-23 21:13:21 # Node ID 15c6a608a7804a09a062eec4f903ee110849af64 # Parent ea7b474ebba78d69ed15b8e034fc93477b8c9fee Somehow temp is working diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -29,14 +29,14 @@ uint32_t packet_sent=1; uint32_t packet_receive=1; -char* itoa(int32_t i, char b[]){ +char* itoa(int16_t i, char b[]){ char const digit[] = "0123456789"; char* p = b; if(i<0){ *p++ = '-'; i *= -1; } - int shifter = i; + uint16_t shifter = i; do{ //Move to where representation ends ++p; shifter = shifter/10; @@ -147,6 +147,7 @@ int32_t p = 1; int32_t i = 1; int32_t d = 1; + // Process things void process() { @@ -155,18 +156,38 @@ void process() Delay(1); // This may not clock at all... might need to send 16 bits first - SPI_I2S_SendData(SPI2, 0xAA); // send dummy data - SPI_I2S_SendData(SPI2, 0xAA); // send dummy data - uint16_t temp1 = SPI_I2S_ReceiveData(SPI2); -// SPI_I2S_SendData(SPI2, 0xAA); // send dummy data -// SPI_I2S_SendData(SPI2, 0xAA); // send dummy data - uint16_t temp2 = 0;//SPI_I2S_ReceiveData(SPI2); + SPI_I2S_SendData(SPI2, 0xAAAA); // send dummy data + //SPI_I2S_SendData(SPI2, 0xAA); // send dummy data + uint16_t temp_pre = SPI_I2S_ReceiveData(SPI2); + + if(temp_pre & 0b0000000000000010) { + ssd1306_DrawString("Fatal Error", 3, 35); + } + else if(temp_pre & 0b0000000000000001) { + ssd1306_DrawString("TC Fault", 3, 35); + } + else { + ssd1306_DrawString("OK ", 3, 35); + } + + uint8_t sign = temp >> 15;// top bit is sign + + + temp_pre = temp_pre >> 2; // Drop 2 lowest bits + + int16_t temp = 0; + if(sign) { + temp = -temp_pre; + } + else { + temp = temp_pre; + } + // Deassert CS Delay(1); GPIO_SetBits(MAX_CS); - int32_t temp = (temp1 << 16) | temp2; ////////////////////////// // Calc internal temp // @@ -186,29 +207,14 @@ void process() ////////////////////////// // Calc external temp // ////////////////////////// - if(temp & 0x7) { - // Something is wrong... - ssd1306_DrawString("!TempCOMMS", 3, 35); - } - - if(temp & 0x80000000) { - // Negative value, drop the lower 18 bits and explicitly extend sign bits - temp = 0xFFFFC000 | ((temp >> 18) & 0x00003FFFF); - } - else { - // Positive value, just drop lower 18 - temp >>= 18; - } - - double temp_centigrade = temp; - if(temp > 0) { GPIO_SetBits(LED_STAT); } char tempstr[9]; - itoa(temp, tempstr); + itoa(temp_pre, tempstr); ssd1306_DrawString("Temp: ", 1, 40); + ssd1306_DrawString(" ", 1, 70); ssd1306_DrawString(tempstr, 1, 70); /*