How to connect rosserial node with atmega32

asked 2021-11-13 22:57:33 -0500

MattR gravatar image

I am attempting to get the avr_chatter.cpp code working with an atmega 32 using this tutorial Using rosserial with AVR and UART . I have updated the avr_time.c and avr_uart.c files with the different registers and changed the MCU declaration in the make file and they all compile with no issues. The problem I am having is that when I try to connect to it with the rosrun rosserial_python serial_node.py I get the error [ERROR] [1636863834.544456]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino. I have tried changing the Baud rate down to 9600 along with checking that all the connections are correct and that I am trying to connect to the right port with no difference. I am running Ros melodic version 1.14.5 But I cant attach my files below due to lack of points so I have linked to my GitHub page instead.

Any help would be greatly appreciated, Mathew

edit retag flag offensive close merge delete

Comments

Please check this thread on this error: https://answers.ros.org/question/2108...

It would be good to know on things that you have already tried

osilva gravatar image osilva  ( 2021-11-14 17:10:42 -0500 )edit

I have tried increasing the buffer size and trying different cables. Something I tested earlier today was to add a flashing light to the while loop in the avr_chatter.cpp file that has been updated on my Github. The led is supposed to turn on for 1 sec and then turn off for 1 sec but instead, it turns on for 4 sec and off for 4 sec. That leads me to believe that it's a problem with the avr_time.c file b/c that is what's controlling the timer but as far as I can tell it should be working properly. I am running the Atmega 32 at 8Mhz.

MattR gravatar image MattR  ( 2021-11-14 20:08:06 -0500 )edit

I believe you are right, this what I found in the Arduino forum.

System clock frequency is supplied as a compile-time parameter (F_CPU). This is specified in the boards.txt file, which also drives the Tools > Boards menu in the IDE.

System clock frequency is not somehow determined from the hardware at compile time or at execution time, it is a given value at compile time.

So when I select Tools > Boards > Arduino Uno, the compiler is told that the clock is 16MHz. If this doesn’t match the actual hardware that I connect, then timings will be off by the ratio of the given vs. actual clock frequencies.

https://forum.arduino.cc/t/verifying-...

osilva gravatar image osilva  ( 2021-11-14 21:02:23 -0500 )edit

Yes, the problem is that I am specifying the F_CPU in the make file and in the avr_chatter.cpp file and have read back the fuses as C4 D9 meaning 8Mhz internal RC clock. I don't know if it is being overwritten somehow or if the math being done as a result of the F_CPU value is somehow getting jumbled? Unfortunately, the atMega 32 is not a supported Arduino chip. If I define the F_CPU value as only 2Mhz I can get the light to the 1sec interval but the Unable to sync with device error continues.

MattR gravatar image MattR  ( 2021-11-14 21:12:04 -0500 )edit

I believe you are approaching the problem correctly. What I suggest to do next is not to run serial_nose.py from rosrun but directly from Python and debug each step. The source code link: https://github.com/ros-drivers/rosser...

One of the suggestions I read is to add rospy.spin() to this code for example that forces a return

osilva gravatar image osilva  ( 2021-11-14 21:38:07 -0500 )edit

I have been on this for about an hour but can seem to figure out where to add the rospy.spin for it to do anything that the While not rospy.is_shutdown() doesn't do. Also, I am probably missing something but how does stepping through the python code help to debug the avr_time.c file. Thanks, Mathew

MattR gravatar image MattR  ( 2021-11-14 23:23:18 -0500 )edit

I thought you said that the clock can be fixed by adjusting at 2MHz so next logical step is to fix the communication with rosserial

osilva gravatar image osilva  ( 2021-11-15 04:59:12 -0500 )edit

Sorry for the mixup I never actually set the clock at 2MHz I only told the code that I did. So I think that there is something that's scaling the clock or the time that's not working quite right.

MattR gravatar image MattR  ( 2021-11-15 10:35:43 -0500 )edit