0

I have been using raspberry pi with a usb to rs232 converter but now I have to use Raspberry Pi's UART pins but I have such a silly problem.

I am using termios.h library in C (http://en.wikibooks.org/wiki/Serial_Programming/termios) and it works very well with converter but when I use UART pins, while I am setting baud rate as

cfsetospeed(&tio,B115200);            // 115200 baud
cfsetispeed(&tio,B115200);            // 115200 baud

baud rate still works at 9600. Is there anouther setting that I have to do with termios library ? If not what should I have to do to change the baudrate ?

Also I have tried with baudrate 4800 and it still works with 9600 when I use UART but with the usb to rs232 converter there is no porblem.

I am using the library

https://github.com/irukeru/TermiosSerialCom

that I have modified and there is no problem with other devices.

irukeru
  • 509
  • 1
  • 10
  • 26
  • Have you looked at the answers to a similar question? - http://stackoverflow.com/questions/4968529/how-to-set-baud-rate-to-307200-on-linux Seems like the capability to set the baud to a higher rate is hardware/system dependent. – Vite Falcon Sep 04 '14 at 08:32
  • And you're setting the attributes for the correct device? Please show how you get and set the attributes, and how you open the device. – Some programmer dude Sep 04 '14 at 08:33
  • 1
    You don't seem to be checking the status returned by `cfsetospeed`/`cfsetispeed` ? – Paul R Sep 04 '14 at 08:36
  • @PaulR you are right. I will check right now. But as I said before I have this problem only with UART pins. There is no 9600 in my C code. – irukeru Sep 04 '14 at 08:38
  • 9600 is usually the default baud rate, so your calls to change the baud rate are probably just failing. – Paul R Sep 04 '14 at 08:40
  • I have checked with stty and default baudrate is 38400 :S I am going to get crazy how can it be at 9600 – irukeru Sep 04 '14 at 08:42
  • 2
    Are you sure you have permission to change the baud rate? Try running the program as the root user to make sure. – Prof. Falken Sep 04 '14 at 10:38
  • I have tried but nothing changed. May be I need to re install raspbian to solve this problem :/ – irukeru Sep 04 '14 at 11:45

1 Answers1

1

Don't see an answer to the OP in this thread, so since I spent much time looking for it and for the sake of public knowledge, here's how to change the default UART baud rate on a Raspberry Pi: Simply edit the file /boot/config.txt to add the following line:

init_uart_baud=115200

You will need root permissions to do so, so don't forget to either start with sudo su and then nano /boot/config.txt or simply sudo nano /boot/config.txt and add the specific line at the end. Then reboot (sudo reboot).

For more /boot/config.txt configuration parameters, check the following link.

Ozk
  • 181
  • 11