I am a beginner with the microcontrollers. I am using the THERMO Click with an an EasyPIC Fusion v7 and a dsPICPIC33EP512MU810. I am now trying to run the example of thermo click which basically is expected to display the temperature in °C thanks to the LCD. But the example is made for an dsPIC30F4013 so I guess I have some changes to do. Actually, the problem is that the board is not reading the programm.
Basis on the example of the Serial flash and MMC for the microcontroller I use, I have tried to made some changes in particular to add some PPS commands and to also the change some lines of the SPI but I still dont have correct results. I don't know actually what to change...
I have used the debugger. At the end, the value of the variable 'temperature' is still '0'.
Here is the programm,
Code: Select all
#include <built_in.h>
#include "Serial_Flash_driver.h"
#include "resources.h"
// LCD module connections
sbit LCD_RS at LATD0_bit;
sbit LCD_EN at LATD1_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
sbit THERMO_CS at LATC2_bit;
sbit THERMO_CS_Dir at TRISC2_bit;
int tmp, intTemp, remTemp;
int counter=0;
float temperature;
char s_temp[16];
short out_size = 0;
short address, buffer;
unsigned short byte[4] = {0, 0, 0, 0};
void MAX31855_Read() {
char buffer;
THERMO_CS = 0;
Delay_ms(100);
byte[0] = SPI3_Read(0);
byte[1] = SPI3_Read(0);
byte[2] = SPI3_Read(0);
byte[3] = SPI3_Read(0);
THERMO_CS = 1;
}
void Display_Temp_Value(void) {
tmp = byte[0];
tmp = tmp << 8;
tmp = tmp | byte[1];
remTemp = tmp >> 2;
remTemp = remTemp & 0x03; // Decimal part of temperature value
temperature = remTemp * 0.25;
intTemp = tmp >> 4; // Intiger part of temperature value
Temperature += intTemp; // Temperature value
Lcd_Out(1,1,"Temperature:"); // Write text in first row
sprintf(s_temp,"%4.2f °C",temperature);
if (out_size > strlen(s_temp)){
Lcd_Out(2, 1, " ");
}
out_size = strlen(s_temp);
Lcd_Out(2, 1 ,s_temp);
}
void main (){
// Setting output frequency to 140MHz
PLLFBD = 70; // PLL multiplier M=70
CLKDIV = 0x0000; // PLL prescaler N1=2, PLL postscaler N2=2
// Configure AN pins as digital
ANSELA=0x00;
ANSELB=0x00;
ANSELC=0x00;
ANSELD=0x00;
ANSELE=0x00;
PPS_Mapping(104, _OUTPUT, _SDO3);
PPS_Mapping(98, _INPUT, _SDI3);
PPS_Mapping(79, _OUTPUT, _SCK3OUT);
THERMO_CS_Dir = 0;
THERMO_CS = 1;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"Thermo test"); // Write text in first row
Lcd_Out(2,1,"starting..."); // Write text in second row
Delay_ms(2000);
SPI3_Init_Advanced(_SPI_MASTER,
_SPI_8_BIT,
_SPI_PRESCALE_SEC_4,
_SPI_PRESCALE_PRI_16,
_SPI_SS_DISABLE,
_SPI_DATA_SAMPLE_END,
_SPI_CLK_IDLE_HIGH,
_SPI_ACTIVE_2_IDLE);
Delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Reading"); // Write text in first row
Lcd_Out(2,1,"temperature ..."); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
while(1) {
MAX31855_Read();
Display_Temp_Value();
counter = 40;
//
if((byte[1] & 0x01) == 0x01){ // Fault detection
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,1,"Error!");
if((byte[3] & 0x01) == 0x01){ // Open circuit fault?
Lcd_Out(1,1,"Open circuit"); // Write text in first row
Delay_ms(1000);
}
//
if((byte[3] & 0x02) == 0x02){ // Short to GND fault?
Lcd_Out(1,1,"Short to GND"); // Write text in first row
Delay_ms(1000);
}
//
if((byte[3] & 0x04) == 0x04){ // Short to Vcc fault?
Lcd_Out(1,1,"Short to Vcc"); // Write text in first row
Delay_ms(1000);
}
}
else{
Display_Temp_Value();
}
Delay_ms(500);
}
}
Aissatou