Hello everyone,
I am a little bit lost and was hoping somebody could help me figuring out what is going on.
My issue is that I use a sim800l module and when I switch it on via a mosfet, my code reboots. I don't really know why and more importantly I don't know how to fix it.
In the attachments I have the pcb layout and a screenshot of the sim800l module I use.
Here is the code that I am running (stripped everything so to just get the bug isolated)
Code:
#include <avr/io.h> #include <util/delay.h> #include <stdio.h> #include "../../library/uart/atmega328p.h" int main() { uint8_t status = MCUSR; MCUSR = 0; if (status & WDRF) { uart_send("RESET: Watchdog\r\n"); } if (status & BORF) { uart_send("RESET: Brownout\r\n"); } if (status & EXTRF) { uart_send("RESET: External\r\n"); } if (status & PORF) { uart_send("RESET: Power on\r\n"); } uart_send("Init\r\n"); DDRC |= (1 << PC0); PORTC |= (1 << PC5) | (1 << PC4); // Set to pull up i2c while(1) { uart_send("On\r\n"); PORTC |= (1 << PC0); // Switch on mosfet _delay_ms(8000); uart_send("Off\r\n"); PORTC &= ~(1 << PC0); // Switch off mosfet _delay_ms(8000); } return 0; }
So when I run this code what I will see is that the "Init" statement gets debugged every time it switches on the mosfet. Obviously I want the "Init" only once and subsequently a alternation of "on" and "off". After the reboot the Sim800l starts to work as it supposes to work, I can send data back to the cloud/internet, it just always comes with an additional reboot. I suspected that it is a voltage drop that caused the reset, but I don't understand why that wouldn't show up in the MCUSR register. The register only shows the reset on powering on the device and afterwards it is completely silent. Is this code correct to look at the MCUSR status?
Ouput debug:
RESET: Watchdog RESET: Brownout RESET: External Init On Init On Off On Init On Off On Init On Off
What I have done so far and didn't work:
- Tried all the fuse settings for the brown out detection 0xFF, 0xFE, 0xFC and 0xF8, doesn't make a difference.
- Added a catch all interrupt vector to see if I got some unhandled interrupt by adding ISR(BADISR_vect), but this doesn't get triggered.
- Soldered a cap over the VCC and GND pin of the Sim800l module, didn't work (10uF and 220uF, didn't have anything else laying around)
- Moved the Sim800l to another output on the pcb, P3 (which also uses a mosfet to switch it on), still reboots.
What I have done so far and did work:
- Put the Sim800l on a breadboard, added wiring and the same caps. Each of the caps, 10uF and 220uF work and it shows "Init" only once.
My thoughts:
- It is not a capacitor or voltage drop issue, otherwise I would have seen a brown out in the MCUSR. I also think that there is already a cap on the Sim800l module (can someone please confirm this)
- Not a code related issue, when I remove the SIm800l and let the code run it works as expected.
- I suspect some issues with the traces on the board that are for P2. But they are almost identical to the ones for P3, only thing I can think of is that VCC for P2 goes under the mosfet body of Q3, which could cause some issues. Mind you Q3 isn't used for the switching process at all, it is a mosfet to switch on my ADC.
Any help in solving this issue would be greatly appreciated.
Regards,
Roy
Update:
- Turns out that the Sim800l has the same issues when moved between P2 and P3, in contrast to what I earlier stated.
- Adding a 220uf Cap to P1 accross VCC and GND doesn't make a difference
- Setting the TWI/I2C inputs to pull ups doesn't change anything