Move SDA/SCL pins on the Arduino Leonardo/micro with custom firmware ?

Hi,

I'm currently designing a project that needs UART, I2C and interrupts. I would also like the UART to be usable while leaving the possibility to flash the device without any interaction from the user.

That last requirement made me change my base arduino for my project from the nano (328p) to the micro (32u4) which has a dedicated UART. After ordering it, i realized that the micro has i2c hooked up to the int2 & 3 pin, which I need. =(

On the nano or the uno, the i2c does not need interrupt to work properly (as far as I understand the schematics of those arduino and the datasheets of those atmel chips).

Is it possible for me to compile a custom bootloader that will reassign sda and scl pins to analog ones (as I do not use them at all) like on the uno/nano ? I thought that "just" reassign pin in pins_arduino.h could be enough. Is that right ?

Or does the micro need to use interrupt to drive the i2c ? If so, do I have any other option to have i2c, hardware uart and 2 interrupt pins free (appart from keeping the nano and use an external i2c to uart bridge, which I have already considered) ?

Thanks

References : Leonardo Micro

Arduino i2c explained

Atmega328p datasheet Atmega32u4 datasheet

LTourist: Is it possible for me to compile a custom bootloader that will reassign sda and scl pins to analog ones (as I do not use them at all) like on the uno/nano ? I thought that "just" reassign pin in pins_arduino.h could be enough. Is that right ?

Or does the micro need to use interrupt to drive the i2c ? If so, do I have any other option to have i2c, hardware uart and 2 interrupt pins free (appart from keeping the nano and use an external i2c to uart bridge, which I have already considered) ?

No, you cannot compile a custom bootloader that reassigns sda and scl pins. No you cannot "just" change pins_arduino.h. This is why it is called hardware.

No, interrupts are not used with I2C, sda and scl.

Can it be solved another way? Yes, [Alternative 1] use the UART (pin 0 and pin 1). Use the I2C (pin2 and pin3) and use pin change interrupts instead of external interrupts. [Alternative 2] use either soft UART to free pin 0 and pin1 as external interrupt pins or soft I2C to free pin 2 and pin3.

BW: All the information is available in the references you posted.

Cheers!

kowalski: No, you cannot compile a custom bootloader that reassigns sda and scl pins. No you cannot "just" change pins_arduino.h. This is why it is called hardware.

I can't found any information about i2c pins had to be wired to specific pins on the ATMega in the datasheet. Could you point me to that piece of information. I'm well aware what hardware means, but it is because I can't find any information about i2c pins in those datasheets that I supposed this was software configurated.

EDIT : nevermind, found it on page 77 :) + I missed the sda/scl mention on the pin configuration page. Again, I only asked about this because I didn't find that information on my first look !

kowalski: Can it be solved another way? Yes, [Alternative 1] use the UART (pin 0 and pin 1). Use the I2C (pin2 and pin3) and use pin change interrupts instead of external interrupts.

Didn't think of that possibility ! Thanks. Before reading the datasheet, I thought arduino's pin change interrupt was achieved using some king of emulation, where the provided library just do some kind of polling those pins. As I understand, the speed concerns expressed here talks about determining the pin that cause the interrupt. Let's says I bypass that lib and use lower level code to catch the interrupt but I do not look for the pin that caused it, is this somewhat speed equivalent to the hardware interrupt (for my own culture) ?

kowalski: [Alternative 2] use either soft UART to free pin 0 and pin1 as external interrupt pins or soft I2C to free pin 2 and pin3.

I forgot to mention that I'd rather not use the software serial but thanks anyway !

kowalski: BW: All the information is available in the references you posted.

I'm more used to 40 pages datasheets than 400 ones. Those piece of infos can get hard to find. Found the chapter on the TWI but didn't find what I was looking for.

Thanks

Pin change interrupts are just as fast as the hardware interrupts, Nick Gammon tested & documented that: http://www.gammon.com.au/forum/?id=11488 Yes, you can just run with seeing that an interrupt occurred on a PORT without determining which pin it was.