0
\$\begingroup\$

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

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

\$\endgroup\$
  • 2
    \$\begingroup\$ Schematic, please :) \$\endgroup\$ – awjlogan May 11 '18 at 12:15
  • \$\begingroup\$ Dont have full schematics yet, I just edited question and uploaded regulator circuit. Other guys suggested that my capacitors are not big enough and I'll definitely try out if thats the case but the 5V and 3.3V Vin are both transformed by this regulator and same capacitors and Vout of 2.7V works but 3.3V doesn't. So I'm not sure if this might be the issue. \$\endgroup\$ – etrusks May 11 '18 at 12:44
  • 1
    \$\begingroup\$ Is the LM1117 below minimum current load when the output is 3V3? \$\endgroup\$ – Jose May 11 '18 at 13:01
  • 1
    \$\begingroup\$ Regulator caps are definitely a problem. See section 8.2.2.1 on the datasheet. When you feed it 3V3, it's not acting as a regulator. You should have 10 uF on the input and minimum 10 uF on the output. \$\endgroup\$ – awjlogan May 11 '18 at 13:02
  • \$\begingroup\$ Ty guys very much for the tips. Much appreciated. I'll be able to test this when I'm at friends house after 3 hours or so but I'll definitely give update how it went. Seems like our capacitors are way off. \$\endgroup\$ – etrusks May 11 '18 at 13:09
2
\$\begingroup\$

From section 8.2.2.1 of the datasheet, it is likely your regulator is unstable. You should have 10 \$\mu\$F on the input and minimum 10 \$\mu\$F on the output. When you feed the regulator 3V3 as an input it is not acting as a regulator; have a look at this question.

\$\endgroup\$
1
\$\begingroup\$

The problem is found! One of the atmegas was plugged into a programming board and this programming board was connected to programmer. Even though programmer was not plugged in anywhere obviously it screwed up something. Disconnecting this programmer from programming board solved the issue.

Thanks to everyone who gave some useful tips :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.