Add scan mode & fix reaction on error readings

This commit is contained in:
eddyem 2018-06-14 16:37:57 +03:00
parent 5e73de26a5
commit ea8d6b4f1b
7 changed files with 60 additions and 19 deletions

View File

@ -1,5 +1,4 @@
- CAN bus: PB8 (Rx), PB9 (Tx)
- USB bus: PA11 (DM), PA12 (DP)
- ADC inputs: PA0 (V12/4.93), PA1 (V5/2), PA3 (I12 - 1V/A), PA6 (V3.3/2)
- controller CAN address: PA13..PA15 (0..2 bits); 0 - master, other address - slave

View File

@ -64,6 +64,7 @@ void iwdg_setup(){
int main(void){
uint32_t lastT = 0, lastS = 0;
int16_t L = 0;
uint8_t scan = 0, gotmeasurement = 0;
char *txt;
sysreset();
SysTick_Config(6000, 1);
@ -87,6 +88,20 @@ int main(void){
sensors_process();
lastS = Tms;
}
if(scan){
if(SENS_SLEEPING == sensors_get_state()){ // show temperature @ each sleeping occurence
if(!gotmeasurement){
//SEND("\nTIME=");
printu(Tms);
usart_putchar('\t');
//newline();
gotmeasurement = 1;
showtemperature();
}
}else{
gotmeasurement = 0;
}
}
if(usartrx()){ // usart1 received data, store in in buffer
L = usart_getline(&txt);
char _1st = txt[0];
@ -99,6 +114,9 @@ int main(void){
case 'O':
sensors_on();
break;
case 'F':
sensors_off();
break;
case 'T': // 'T' - get temperature
showtemperature();
break;
@ -123,6 +141,14 @@ int main(void){
printu(getCANaddr());
newline();
break;
case 'S':
SEND("Start scan mode\n");
scan = 1;
break;
case 'P':
SEND("End scan mode\n");
scan = 0;
break;
#ifdef EBUG
case 'd':
case 'g':
@ -136,13 +162,16 @@ int main(void){
#endif
default: // help
SEND("'C' - show coefficients\n"
"'O' - turn On sensors\n"
"'T' - get raw temperature\n"
"'R' - reinit I2C\n"
"'V' - very low speed\n"
"'L' - low speed\n"
"'H' - high speed\n"
"'G' - get CAN address\n"
"'F' - turn oFf sensors\n"
"'H' - high speed\n"
"'L' - low speed\n"
"'O' - turn On sensors\n"
"'P' - stoP themperature scan\n"
"'R' - reinit I2C\n"
"'S' - Start themperature scan\n"
"'T' - get raw temperature\n"
"'V' - very low speed\n"
#ifdef EBUG
"\t\tTEST OPTIONS\n"
"'d' - discovery\n"

View File

@ -210,11 +210,11 @@ newline();
MSG("try more\n");
if(!write_i2c(Taddr[i], TSYS01_RESET)) i2c_setup(CURRENT_SPEED); // maybe I2C restart will solve the problem?
}
if(j == 5){
MSG("error start monitoring, reset\n");
/*if(j == 5){
MSG("error start monitoring, reset counter\n");
sensors_on(); // all very bad
return 1;
}
}*/
}
return 0;
}
@ -224,6 +224,7 @@ static uint8_t gettempproc(){
uint8_t i;
for(i = 0; i < 2; ++i){
if(!(sens_present[i] & (1<<curr_mul_addr))) continue; // no sensors @ given line
Temperatures[curr_mul_addr][i] = NO_SENSOR;
uint8_t err = 1;
MSG("Sensor #");
#ifdef EBUG
@ -311,21 +312,28 @@ void showtemperature(){
}
if(Ntemp_measured == 0){
SEND("No right measurements\n");
return;
}
for(a = 0; a <= MUL_MAX_ADDRESS; ++a){
for(p = 0; p < 2; ++p){
if(!(sens_present[p] & (1<<a))) continue; // no sensor
char b[] = {'T', a+'0', p+'0', '=', '+'};
if(!(sens_present[p] & (1<<a))){
SEND("-31000\t"); // NO_SENSOR
continue; // no sensor
}
//char b[] = {'T', a+'0', p+'0', '=', '+'};
int16_t t = Temperatures[a][p];
if(t < 0){
b[4] = '-';
//b[4] = '-';
t = -t;
usart_putchar('-');
}
while(ALL_OK != usart_send_blocking(b, 5));
//while(ALL_OK != usart_send_blocking(b, 5));
printu(t);
newline();
usart_putchar('\t');
//newline();
}
}
newline();
}
// finite state machine for sensors switching & checking
@ -386,6 +394,10 @@ MSG("->gather\n");
case SENS_GATHERING: // scan all sensors, get thermal data & calculate temperature
if(sensors_scan(gettempproc)){
lastSensT = Tms;
if(Nsens_present != Ntemp_measured) i2c_setup(CURRENT_SPEED);
Sstate = SENS_SLEEPING;
MSG("->sleep\n");
/*
if(Nsens_present == Ntemp_measured){ // All OK, amount of T == amount of sensors
MSG("->sleep\n");
Sstate = SENS_SLEEPING;
@ -393,7 +405,7 @@ MSG("->sleep\n");
MSG("gather error ->start\n");
i2c_setup(CURRENT_SPEED);
Sstate = SENS_START_MSRMNT;
}
}*/
}
break;
case SENS_SLEEPING: // wait for `SLEEP_TIME` till next measurements

View File

@ -32,6 +32,8 @@
#define SLEEP_TIME (3000)
// error in measurement == -300degrC
#define BAD_TEMPERATURE (-30000)
// no sensor on given channel
#define NO_SENSOR (-31000)
typedef enum{
SENS_INITING // power on

Binary file not shown.

View File

@ -26,7 +26,7 @@
extern volatile uint32_t Tms;
static int datalen[2] = {0,0}; // received data line length (including '\n')
int linerdy = 0, // received data ready
volatile int linerdy = 0, // received data ready
dlen = 0, // length of data (including '\n') in current buffer
bufovr = 0, // input buffer overfull
txrdy = 1 // transmission done

View File

@ -31,7 +31,6 @@
// macro for static strings
#define SEND(str) do{}while(LINE_BUSY == usart_send_blocking(str, sizeof(str)-1))
#define NEWLINE() do{}while(LINE_BUSY == usart_send_blocking('\n', 1))
#ifdef EBUG
#define MSG(str) do{SEND(__FILE__ " (L" STR(__LINE__) "): " str);}while(0)
@ -48,7 +47,7 @@ typedef enum{
#define usartrx() (linerdy)
#define usartovr() (bufovr)
extern int linerdy, bufovr, txrdy;
extern volatile int linerdy, bufovr, txrdy;
void usart_setup();
int usart_getline(char **line);