I have a AVR-P40-USB-8535 prototyping board and ubuntu linux. I’ve finally decided to try and get this whole rs232 thing working because it seems like it could greatly simplify debugging. The only problem is, I can’t actually get it to work. I can compile for and program the uC just fine, but whenever I use gtkterm to try and connect, all I get is
Control signals read: Inappropriate ioctl for device
What USB device are you using? Maybe the FT232 breakout?
I usually open a terminal and type “tail -f /var/log/messages” before connecting the USB device to the pc, then among other informations I see which file is associated with the FT232, usually /dev/ttyUSB0, then type Ctrl-C to quit.
I do not use gkterm to see debugging data, I prefer to use “sudo stty 19200 -F /dev/ttyUSB0” where 19200 is the baudrate (see “man stty” for other useful options), then just “sudo cat /dev/ttyUSB0” and the debug data is printed to the treminal itself. Again, Ctrl-C to quit.
Awesome - that looks much better than what I was doing before. I get this from tail:
Oct 14 10:37:25 ubuntu kernel: [193674.802125] usb 1-3: new full speed USB device using ohci_hcd and address 12
Oct 14 10:37:26 ubuntu kernel: [193675.779618] usb 1-3: configuration #1 chosen from 1 choice
Oct 14 10:37:26 ubuntu kernel: [193675.781067] ftdi_sio 1-3:1.0: FTDI USB Serial Device converter detected
Oct 14 10:37:26 ubuntu kernel: [193675.781075] drivers/usb/serial/ftdi_sio.c: Detected FT232BM
Oct 14 10:37:26 ubuntu kernel: [193675.781234] usb 1-3: FTDI USB Serial Device converter now attached to ttyUSB0
Oct 14 10:37:29 ubuntu kernel: [193677.442007] usb 1-3: usbfs: interface 0 claimed by ftdi_sio while 'brltty' sets config #1
Oct 14 10:37:29 ubuntu kernel: [193677.443844] ftdi_sio 1-3:1.0: device disconnected
Oct 14 10:37:29 ubuntu kernel: [193676.585160] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
Oct 14 10:37:46 ubuntu kernel: [193686.244058] usb 1-3: USB disconnect, address 12
It says that the device disconnects before I get a chance to do anything(3 seconds between when I connect and when it disconnects, and then another 17 before it says the usb device is disconnected). Could this be a problem with the code, or do you have any more ideas?
Thanks for all the help - I finally got it to connect. While I couldn’t use your method of reading messages, I managed to get gtkterm to read them. I’ll figure out why later - I have no preference which to use, so for me it’s just whichever works. The problem was apparently ubuntu specific, and I just had to remove the brltty packages.
Now my problem is that all I receive is giberish, something which is probably more difficult to solve than it not connecting. Any thoughts? In any case, thanks for all the help.
I found the problem, if anybody runs into this in the future - while my code seemed to be set up at 9600 bps, when I set my terminal to receive at 1200 bps I got the correct output. I’m not sure what’s up with that, but whatever, I’ll go for it. If anybody does know, however, I would be very interested.
Ubuntu distros come with the brltty package installed. This package conflicts with using the device as a plain serial port. Upon insertion the brltty driver takes over the device and disconnects the /dev/ttyUSBn device. The solution to this is to remove or disable the brltty package. On Ubuntu you can do this with
NetElemental:
I found the problem, if anybody runs into this in the future - while my code seemed to be set up at 9600 bps, when I set my terminal to receive at 1200 bps I got the correct output. I’m not sure what’s up with that, but whatever, I’ll go for it. If anybody does know, however, I would be very interested.
Thanks for all the great help!
I was pretty confused with this as well. I tried a few values of baudrate and I also didn’t know what was the clock freq of my AVR (Im a noob). I read some of the data sheets (the big 300+ page manual) and it started to make more sense.
So after much trying, I found out that you can use the default multiplier (16) up to 4800 bauds. If you jump to 9600, there’s too much errors or something (the data specs also show this), and it shows garbage. If you want more than 4800 bauds in asynchronous mode, you can set the U2X bit in the USCRA register to 1, and then the multiplier is 8 and you can get higher frequencies. I havent tried more than 9600 though.
This is more or less what I have now:
/* This is the default clock speed (for the uc and the UART) for the AVR Atmega32 */
#define OSCSPEED 1000000 /* in Hz */
/* U2X
* Writing this bit to one will reduce the divisor of the baud
* rate divider from 16 to 8 effectively doubling the transfer
* rate for *asynchronous* communication.
*/
UCSRA = UCSRA | 0b00000010;
unsigned int BaudRate = OSCSPEED / (8 * Baud) - 1;
//set BaudRate into registers
UBRRH = (unsigned char) (BaudRate>>8);
UBRRL = (unsigned char) BaudRate;
One thing to check. 1200 baud is 1/8th of 9600 baud, so I’d guess that clock divider on your chip is set at the default value of 8. You should be able to set it to 1 at the start of your program so that the core runs at full speed.