# UART - Writing and reading AT commands

I am working with a B-L072Z-LRWAN1 board and a 8pya00-simcom-evb v1.02 board with SIM7000E. This SIM module operates through AT commands and I need to send these commands through an UART connected between mentioned boards.

I have already set up the UART in the B-L072Z-LRWAN1 and I am able to transmit bytes of information, but I am not sure how to send AT commands.

Which is the format I have to use to send the commands? Do I use char variables? Do I use uint8_t variables and add '0' at the end to make them chars? Do I need to add \n\r at the end of the command?

I am a little bit confused so I need your help. Thank you!

• I remember, that it was necessarey to send line feeds at the end of a command. The format of your variables doesn't matter. AT commands are ascii based. All values must be translated to ascii. – A.R.C. Nov 19 '18 at 10:57
• By the way, on STM32 uint8_t and char are both 8-bit variables. I don't know why you want to add a '0' at the end. Do you mean char arrays and terminating them with 0? – A.R.C. Nov 19 '18 at 10:59
• Yes, I meant char arrays terminated to '0', sorry. If I initialize a char array as char command = "AT\n\r", do I need to send strlen(command)-1 bytes to avoid sending the '0'? – Pablo Díaz Amores Nov 19 '18 at 11:08
• I think the '0' will be ignored after \n\r so it doesn't matter. I started my first AT Command project with an uart to USB cable. That way it was easy to test simple commands by typing into the PC terminal programm and try different settings. Maybe this will help you too. – A.R.C. Nov 19 '18 at 13:49
• An extra '0' though would screw up the next command you send. Luckily strlen() is defined as The strlen() function calculates the length of the string s, excluding the terminating null byte ('\0'). So stren(command) already excludes the 0 byte. I would say most likely cause of problem would be a mismatch in BAUD, parity or number of stop bits. – Goswin von Brederlow Nov 19 '18 at 15:28

char and uint8_t should be equivalent on ARM, in other words, char should be unsigned, but there are toolchains out there with char by default signed. It does not matter in this case anyway, because AT commands would only use characters in the [0-127] range.
Adding a \r at the end of the command is mandatory, \n and \x00 would probably be ignored, but better not send them. Responses are terminated with \r\n (not \n\r)