I already posted this question on avrfreaks but so far I'm not getting many responses so decided to ask here as well.
So I'll start by telling little bit how this project looks together for the basic idea. We have Microchip RN4020 Bluetooth module(3.3V device), Cypress CY15B102Q FRAM(3.3V device) and two Atmega328p.
The idea is to light up neopixel WS2812B(5V device) leds depending what data comes in from Bluetooth module. It can be both just a single color or different animated movements. So we save data about animated movements in FRAM. Problem with one Atmega328 was that it couldn't manage in time to both receive UART data about new animation and save it to FRAM and light up LEDS frame by frame without missing some data from UART(because had to tun off interrupts at the time of lighting up LEDS).
These devices get power from LM1117 Regulator that's supposed to give 3.3V output when given in 5V.
So now one Atmega328p is responsible for getting UART data from RN4020 and saving them to FRAM and the another one takes data through SPI from FRAM and lights up leds. Problem is of course sharing the same FRAM by these two Atmega328p so I decided to dedicate 2 pins that would indicate whether or not FRAM is in use by any of these two Atmegas.(if in use PIN is high, if not low). The other Atmega looks at this and waits when SPI is not used by another Atmega and only at this point turn on SPI and start using FRAM. When SPI is not used those pins are set as inputs so they wouldn't screw the signal.
Here are the functions that are responsible for turning SPI on/off
void turn_SPI_on()
{
if(!spi_is_enabled){
DATA_PORT |= (1 << FRAM_USED_BY_MCU2);
PRR &= ~(1 << PRSPI);
/* Set MOSI and SCK, MOSI and SS output, all others input */
SPI_DDR = (1<<SS) | (1<<MOSI) | (1<<SCK);
SPI_PORT = (1 << SS); //slave select high
/* Enable SPI, Master, set clock rate fck/4 */
SPCR = (1<<SPE)|(1<<MSTR);
SPSR = (1 << SPI2X); //double SPI speed
spi_is_enabled = 1;
}
}
void turn_SPI_off()
{
if(spi_is_enabled){
SPCR = 0;
SPSR = 0;
//set everything to input
SPI_DDR = 0;
SPI_PORT = 0;
spi_is_enabled = 0;
DATA_PORT &= ~(1 << FRAM_USED_BY_MCU2);
}
}
So the interesting thing is that when LM1117 gets input voltage of 3.3V from UART USB module it gives output of 2.7V as datasheet suggests and its still fine because everything still works with this voltage. (Both Atmegas can share the same FRAM though SPI without any problems at all). Now the fun fact happens when LM1117 received 5V in its input and gives 3.3V ouput which should work the same way. Now the second Atmega which is supposed to light up leds reads the values from FRAM all wrong while the Atmega responsible about receiving data from UART still can access FRAM without any problems. If I unplug the SPI CLOCK(SCK) wire from 1st Atmega(the one responsible for UART) 2nd Atmega starts accessing correctly.
Can you guys give me any ideas why this might happen? Remember that this is the same program and works with 2.7V power supply but doesnt with 3.3V.
LM1117 regulator circuit
EDIT : One more potentially important thing - If power supply V_in = 3.3V (V_out = 2.7V), its taken from UART USB module, if power supply V_in = 5V (V_out = 3.3V), its taken from LRS-50-5 power supply