Questions for implementing MODBUS using AVR


Thread Starter

Javad babaee


I have 8 analog channels in atmega128 to read. I want to read these values and send them to master when requested (using RS485 4-wire and MODBUS protocol)

I think I have to wait for a call from master in my code (I am going to use codevisionAVR); so I'd like to set my ADC settings to work in free running mode and the analog values be ready when ever I need to read them and send to master.

But from datasheet, it seems that the channel ADC is working on, should be set in ADMUX register, so it seems free running mode will convert only 1 channel input, I have 8!
I'm afraid I go for reading analog values and get a call from master at the same time and miss that!
Any comments/suggestions?
This is my first code for USART

How I should get notified the master is sending a request to check if it's sending my address, in C++ for AVR?
Thank you in advance for your help

ahmed esmaeil

you can't synchronize the master request and the ADC read. if the ADC value isn't ready in 3.5 time of the modbus standard you will miss the response timeout of the master.

so I suggest that you scan the adc continuously and then store the values in a register(s). and when the master issues a read request, the data will be ready to be sent waiting in those registers.