gioblu/PJON

SoftwareBitBang Atmega32A support

Nume1977 opened this issue · 1 comments

I really love this protocol, and recently i updated one of my projects from a Atmega328p to a Atmega32A (44 pin variant), but it is not supported by Pjon (throws erros when compiling, mainly because of "'PJON_IO_PIN_TO_PORT_REG' was not declared in this scope" ) and my guess is because of the pinouts.

This chip is available on the MightyCore boards along with the 1244/644/324/164 etc.

Is there any change for this chip to be supported, or point me in the right way to add the pin settings?

Ciao @Nume1977 thank you for your compliments and welcome :)
It is relatively easy to add support for new chips: https://github.com/gioblu/PJON/blob/master/src/interfaces/ARDUINO/PJON_IO.h
In particular here: https://github.com/gioblu/PJON/blob/master/src/interfaces/ARDUINO/PJON_IO.h#L97
You see how the registers are conditionally defined for the 88/168/328, you just need to:

  1. Duplicate this condition
  2. Change the constant used to identify the MCU
  3. Pass the right registers and port groups according to the datasheet

When you got the IO working, test SoftwareBitBang using the local NetworkAnalysis example.
If it does not work or performance is not optimal the ATmega32 needs a custom timing configuration:
https://github.com/gioblu/PJON/blob/master/src/strategies/SoftwareBitBang/Timing.h#L28

To do so:

  1. Duplicate the 88/168/328 condition linked above
  2. Change the constant name used to identify the MCU
  3. Tweak the value of SWBB_READ_DELAY.

In most cases this is enough to get it working optimally, if you cannot achieve optimal performance SWBB_BIT_WIDTH may need to be slightly tweaked on the ATmega32A side.

Be careful and always test in both directions (inverting the roles of mcu) to be sure communication works fine in both cases.
Let me know how it goes and feel free to join our gitter chat for direct support if that is required: https://gitter.im/gioblu/PJON

See also the SoftwareBitBang troubleshooting section to have additional info:
https://github.com/gioblu/PJON/wiki/SoftwareBitBang-troubleshooting