- Sat Oct 13, 2007 6:53 pm
#36452
Hey,
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
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
Code: Select all
The command for gtkterm I'm using is
Control signals read: Inappropriate ioctl for device
Code: Select all
The code on the uC is
sudo gtkterm -p /dev/bus/usb/001/010
Code: Select all
Any help?/*
5-10-07
Copyright Spark Fun Electronics© 2007
Nathan Seidle
nathan at sparkfun.com
Example basic printf input/output
*/
#include <stdio.h>
#include <avr/io.h>
#define FOSC 16000000
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1
#define sbi(var, mask) ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask) ((var) &= (uint8_t)~(1 << mask))
#define STATUS_LED 0
//Define functions
//======================
void ioinit(void); // initializes IO
static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
void delay_ms(uint16_t x); // general purpose delay
//======================
int main (void)
{
uint8_t x = 0;
ioinit(); //Setup IO pins and defaults
while(1)
{
x++;
printf("Test it! x = %d\r\n", x);
sbi(PORTB, STATUS_LED);
delay_ms(500);
cbi(PORTB, STATUS_LED);
delay_ms(500);
}
return(0);
}
void ioinit (void)
{
//1 = output, 0 = input
DDRB = 0xFF ^ (1 << 6);//0b11101111; //PB4 = MISO
DDRC = 0xFF;//0b11111111; //
DDRD = 0xFF ^ (1 << 0);//0b11111110; //PORTD (RX on PD0)
//USART Baud rate: 9600
UBRRH = MYUBRR >> 8;
UBRRL = MYUBRR;
UCSRB = (1<<RXEN)|(1<<TXEN);
UCSRC = (1<<URSEL)|(3<<UCSZ0);
stdout = &mystdout; //Required for printf init
}
static int uart_putchar(char c, FILE *stream)
{
if (c == '\n') uart_putchar('\r', stream);
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return 0;
}
uint8_t uart_getchar(void)
{
while( !(UCSRA & (1<<RXC)) );
return(UDR);
}
//General short delays
void delay_ms(uint16_t x)
{
uint8_t y, z;
for ( ; x > 0 ; x--){
for ( y = 0 ; y < 80 ; y++){
for ( z = 0 ; z < 40 ; z++){
asm volatile ("nop");
}
}
}
}