comments and details
This commit is contained in:
@@ -27,13 +27,18 @@ void kraftsensor_init(){
|
|||||||
void do_kraftsensor(){
|
void do_kraftsensor(){
|
||||||
uint16_t m_data[4];
|
uint16_t m_data[4];
|
||||||
|
|
||||||
|
/* read 2 16bit values and merge to 32bit signed integer */
|
||||||
readReg(1,0,2);
|
readReg(1,0,2);
|
||||||
if(wait_receive(2, m_data, 10))
|
if(wait_receive(2, m_data, 10)){
|
||||||
kraftsensor_valid = 0;
|
kraftsensor_valid = 0;
|
||||||
|
printf("modbus error\n\r");
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
kraftsensor_valid = 1;
|
kraftsensor_valid = 1;
|
||||||
int32_t tmp = (uint32_t)m_data[0]<<16;
|
int32_t tmp = (uint32_t)m_data[0]<<16;
|
||||||
tmp |= m_data[1];
|
tmp |= m_data[1];
|
||||||
|
|
||||||
|
/* conversion magic to milliNewton */
|
||||||
kraftsensor_value = ((tmp + 539363)*9.81)/177.380;
|
kraftsensor_value = ((tmp + 539363)*9.81)/177.380;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +55,6 @@ uint8_t wait_receive(uint8_t len, uint16_t dest[], uint8_t timeout){
|
|||||||
if(receiveOkay) { //if this fails, there was either no response or a crc error
|
if(receiveOkay) { //if this fails, there was either no response or a crc error
|
||||||
if(rxbuffer[1]&0x80) { //client responded with an error code
|
if(rxbuffer[1]&0x80) { //client responded with an error code
|
||||||
//handle the error
|
//handle the error
|
||||||
printf("error\n\r");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
3
main.c
3
main.c
@@ -64,7 +64,6 @@ static void avr_init()
|
|||||||
wdt_reset(); // wdt reset ~ every <2000ms
|
wdt_reset(); // wdt reset ~ every <2000ms
|
||||||
|
|
||||||
timer0_init();// Timer0 millis engine init
|
timer0_init();// Timer0 millis engine init
|
||||||
//timer3_init();
|
|
||||||
uart_init();
|
uart_init();
|
||||||
|
|
||||||
sei(); //re-enable global interrupts
|
sei(); //re-enable global interrupts
|
||||||
@@ -148,7 +147,7 @@ int main()
|
|||||||
while(1); //Reboot the board
|
while(1); //Reboot the board
|
||||||
}
|
}
|
||||||
|
|
||||||
char SubString[] = "/Filamentanlage/04_Messmodul/set/#";
|
char SubString[] = "/Filamentanlage/05_Abzug/set/#";
|
||||||
mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
mqtt_rc = MQTTSubscribe(&mqtt_client, SubString, QOS0, messageArrived);
|
||||||
printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
printf("Subscribed (%s) %ld\r\n", SubString, mqtt_rc);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user