2

I am using an ATmega328P with internal clock (8 MHz) with a SIM800L module. The default baud rate of the SIM800L is 115,200 baud and I can't make them talk to each other correctly. Although I was able to make them talk very easily at a baud rate of 9600 baud. But now, with a new SIM800L I can't.

Question:

How to change the default baud rate of a SIM800L? Is it possible to run an ATmega328P at a baud rate of 115,200 baud?

Thanks in advance!

EDIT:

I know that I can run atmega328p at baud rate of 115200 with different crystal, but is it possible to it using internal crystal.

2

According to Adafruit's pdf specsheet SIM800+Series_Serial+Port_Application+Note_V1.01.pdf, the SIM800 is set up to auto-baud when it starts out:

SIM800 series is designed in autobauding mode by default. Autobauding allows SIM800 series to automatically detect the baud rate of the host device. In application, host device must to synchronize the baud rate with SIM800 series. Host device must firstly send characters "AT" or "at" to synchronize the baud rate. It is recommended to send "AT" until host device receives the "OK" response, which means host device and SIM800 series are correctly synchronized. Once the baud rate is synchronized, it is suggested to use AT command "AT+IPR" to set SIM800 series baud rate according the host baud rate. ...

So, you might arrange your software to keep trying at 9600 bps. If you get an ok connection at that rate, you can either keep using it or shift to a higher frequency via "AT+IPR". [I haven't read the spec sheet enough to know whether that default autobauding is always on, or might be turned off somehow.]

As serial-data bps goes up, required clock accuracy becomes tighter. Where a couple of percent error may be ok at 9600 bps, under a percent probably is needed at 115200 bps.

On several boards I've measured RC oscillator frequency errors of about 2%, which according to question How critical are UART frequencies? might or might not be good enough to allow high-speed serial communications.

If you can measure your ATmega328P's RC oscillator frequency, you can then apply a correction factor at startup. In the spec sheet (eg Atmel-8271J-AVR-ATmega-Datasheet_11/2015), see §9.12.1, OSCCAL – Oscillator Calibration Register.

Your program can start out with the RC oscillator using the factory-set value, and then can load your own calibration value into the Oscillator Calibration Register to shift RC frequency as needed to make the board work ok for 115200 bps serial data. Or, you can overwrite (in EEPROM fuse or signature area) the factory-set value with your own number.

Figure 32-37, ATmega48PA: Calibrated 8MHz RC Oscillator Frequency vs. OSCCAL Value, shows typical frequencies for various Oscillator Calibration Register values. It is possible to tune clock frequency close enough that serial communications should work ok.

High-range byte values 144 through 160 typically move frequency from around 7.4 MHz to 8 MHz (at 85℃). In this range, each count shifts clock frequency by about 0.5%. See the figure for details. For example, if value 158 gives an RC frequency of about 7820 KHz, then value 159 might raise the RC frequency to about 7860 KHz.

Low-range entries 96 through 112 move frequency from around 7.5 MHz to 8.5 MHz. This overlap makes it necessary to try both low-range and high-range values when looking for the best Calibration Register value.

Note, there are inexpensive cymometers (frequency counters) on ebay, which can measure oscillator frequencies accurately enough to enable the calibration suggested above.

2

As you say, SIM800L default baud rate is 115200. So, you have to set that baud rate on arduino side. And yes, it is possible to run an ATmega328P at a baud rate of 115200 baud.

You can use the SoftwareSerial library and define your own tx and rx pin and set baud rate according to your requirement.

#include <SoftwareSerial.h>   // SoftwareSerial library
SoftwareSerial mySerial(2,3); // RX, TX for your module

void setup()
{
   mySerial.begin(115200);      // Set your buad rate
}

And you can also do without this library.

void setup()
{
  Serial.begin(115200);        // Set your baud rate
}
  • Sorry but not true, you can change the SIM800's baud rate with the appropriate AT command, AT+IPR (as already mentioned in an other answer). – Bence Kaulics Mar 21 '17 at 18:31
  • @BenceKaulics Thank you for this information. – Hasan Mar 22 '17 at 0:51
1

Well I do not think that the default baud rate is 115200. The default setting is autobaud which does not support 115200 baudrate. From the datasheet.

serial port properties

You can change it with the already mentioned AT+IPR command. From the AT manual you can also check that the default setting is autobaud, and also the selectable baud rates.

Note: User can use AT command “AT+IPR=x” to set a fixed baud rate and the setting will be saved to non-volatile flash memory automatically.

AT+IPR command

If you use 57600 you will probably alright and you do not even have to change the baud rate settings as this value is supported.

0

From what I have read so far, the problem is that there is no good divisor from an 8 MHz oscillator to get a within-spec baud rate above 57,600. Using the internal oscillator is also susceptible to variation with temperature, so that appears to be bad solution as well in many applications. The problem being that it may work on one MPU, but not with the next one.

As far as I can tell, the best solution is to use a 7.372800 MHz oscillator. This results in the processor running a bit slower, but it also results in the baud rate divisors being spot-on for almost all the standard and popular baud rates, meaning you should be able to run to at least 921,000 baud.

If anyone has a better solution, I would love to hear it, as I am dealing with a similar issue in something I intend to take into production that will be in a variety of environments.

0

You can change the baud rate to 9600 on the SIM800L with the command:

AT+IPR=9600

Then to save this (to last between boot cycles), give the command:

AT&W

To see the saved settings, give the following command:

AT&V 

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.