Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TWI in slave mode using port PF2 and PF3 #66

Open
rlivio opened this issue Jan 28, 2020 · 3 comments
Open

TWI in slave mode using port PF2 and PF3 #66

rlivio opened this issue Jan 28, 2020 · 3 comments
Assignees

Comments

@rlivio
Copy link

rlivio commented Jan 28, 2020

I need to use the ATmega4809 with I2C configured in slave mode using pins PF2 and PF3.
The only way to obtain that is to add:

PORTMUX.TWISPIROUTEA |= TWI_MUX;
TWI0.DUALCTRL = TWI_ENABLE_bm;

after the Wire.begin(4);

Probably the instruction: PORTMUX.TWISPIROUTEA |= TWI_MUX is missing inside the function TWI_SlaveInit() in file twi.c

Those who have more experience than me can check.

Livio

@tomalmy
Copy link

tomalmy commented Oct 20, 2020

I've used the TWI on a Nano Every board both master and slave simultaneously (it takes some mods to twi.c to re-enable that functionality). But in answer to your question, because PA2/PA3 and PF2/PF3 are bonded together on the board it is not necessary to set PORTMUX or DUALCTRL, nor will it make any practical difference. The TWI master and slave interfaces will always share the same SDA/SCL pins on the board.

@curiosity4809
Copy link

Hey tomalmy,

can you tell me which functionalys in twi.c youve made to use master and slave in same time?

@tomalmy
Copy link

tomalmy commented Sep 13, 2021

The issue is that twi_mode is used for both master and slave operation. And executing either TWI_MasterInit or TWI_SlaveInit precludes executing the other.

I added a new variable static volatile TWI_MODE_t twi_smode; Then all the slave functions are changed to use twi_smode instead of twi_mode. Also in TWI_SlaveInit change the last line to:
TWI0.MCTRLA |= TWI_ENABLE_bm; // PATCH change to |= so as not to disable Master operation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants