|
|
|
|
@ -7,12 +7,7 @@
|
|
|
|
|
|
|
|
|
|
uint16_t holdingRegisters[4];
|
|
|
|
|
|
|
|
|
|
void timer0100us_start(void) {
|
|
|
|
|
TCCR0B|=(1<<CS01); //prescaler 8
|
|
|
|
|
TIMSK0|=(1<<TOIE0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return raw ADC data
|
|
|
|
|
// return raw ADC data
|
|
|
|
|
uint32_t HX711_get_data(uint8_t clk_PIN, uint8_t data_PIN, uint8_t gain_for_next_conv){
|
|
|
|
|
uint32_t data = 0;
|
|
|
|
|
for(uint8_t i = 0; i < 24; i++){ //Start 24bit transmission
|
|
|
|
|
@ -63,29 +58,24 @@ uint32_t HX711_get_data(uint8_t clk_PIN, uint8_t data_PIN, uint8_t gain_for_next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void modbusGet(void) {
|
|
|
|
|
if (modbusGetBusState() & (1<<ReceiveCompleted))
|
|
|
|
|
{
|
|
|
|
|
switch(rxbuffer[1]) {
|
|
|
|
|
case fcReadHoldingRegisters:
|
|
|
|
|
PORTC ^= 1 << 1;
|
|
|
|
|
// _delay_ms(10);
|
|
|
|
|
// PORTC &= ~(1 << 1);
|
|
|
|
|
if (modbusGetBusState() & (1<<ReceiveCompleted))
|
|
|
|
|
{
|
|
|
|
|
switch(rxbuffer[1]) {
|
|
|
|
|
case fcReadHoldingRegisters:
|
|
|
|
|
PORTC ^= 1 << 1; // toggle led
|
|
|
|
|
|
|
|
|
|
while(PINB & (1<<4)); // wait for data ready
|
|
|
|
|
|
|
|
|
|
uint32_t tmp = HX711_get_data(3, 4, 128);
|
|
|
|
|
//int32_t tmp = -1000;
|
|
|
|
|
holdingRegisters[0] = tmp & 0xFFFF;
|
|
|
|
|
holdingRegisters[1] = (tmp>>16) & 0xFFFF;
|
|
|
|
|
modbusExchangeRegisters(holdingRegisters,0,4);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: {
|
|
|
|
|
modbusSendException(ecIllegalFunction);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
modbusExchangeRegisters(holdingRegisters,0,4);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
modbusSendException(ecIllegalFunction);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(void){
|
|
|
|
|
@ -96,13 +86,12 @@ int main(void){
|
|
|
|
|
modbusInit();
|
|
|
|
|
sei();
|
|
|
|
|
|
|
|
|
|
timer0100us_start();
|
|
|
|
|
/* modbus tick timer */
|
|
|
|
|
TCCR0B|=(1<<CS01);
|
|
|
|
|
TIMSK0|=(1<<TOIE0);
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
modbusGet();
|
|
|
|
|
//PORTC ^= 1 << 0;
|
|
|
|
|
//_delay_ms(100);
|
|
|
|
|
//PORTC &= ~(1 << 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|