usb_serial and Teensy 2

Status
Not open for further replies.

jack

Active member
Hi -

One of Paul's cool libraries that I have'nt used yet is usb_serial,

so today I fired it up on a T2, and tried to connect with a PC file

manager pgm that has an RS232 I/O option, via usb. (I've done

this before with other hardware, including bit-banging it with a T2

-> MAX3232 -> FT232R -> PC, which connected to the PC file manager

pgm with little fuss...)


So what I expect to happen is that after transmitting the contents of

the buffer the PC program should pop up a "connected" icon, and send

back an "ACK" message.


What actually happens is nothing, until I reset the Teensy, at which

point the PC pgm pops up its "connected" icon...


I can see the serial port come up in Device Manager, and the PC pgm

can see it too (It shows what port it's connected to...), and there's

no handshaking involved.


Most likely I've made some dumb coding error - Can anyone see what

I'm missing?

Thanks...


usb_init();

while (!usb_configured());

_delay_ms(1000);

while (PIND & (1<<1)) {}; // loop while PIND.1 High

// start up PC terminal pgm , then pull PIND.1 low

usb_serial_write(buffer,14); // sends "Connect" command,

// should see connected icon now...

usb_serial_flush_output(); // just in case, but no joy...

// but, when I give up and reset the T2, the icon appears, so
// apparently the msg is sent, but is'nt received by the PC pgm
// until the reset...?
 
Thanks for taking the time to read this. The whole enchilada:


include <stdint.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

#include "usb_serial.h"

#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define CPU_16MHz 0x00
#define CPU_8MHz 0x01
#define CPU_4MHz 0x02
#define CPU_2MHz 0x03
#define CPU_1MHz 0x04
#define CPU_500kHz 0x05
#define CPU_250kHz 0x06
#define CPU_125kHz 0x07
#define CPU_62kHz 0x08

#define LED_ON (DDRD |= (1<<6),PORTD |= (1<<6))
#define LED_OFF (PORTD &= ~(1<<6))


int main(void)

{
unsigned char buffer[] = {0x16,0x16,0x16,0x10,0x02,0x01,0x40,0x00,
0x01,0x02,0x10,0x03,0x10,0xBF};

CPU_PRESCALE(CPU_16MHz);

// config I/O pins

DDRB &= ~((1<<0) | (1<<1) | (1<<2) | (1<<3) | // PORTB -> Inputs

(1<<4) | (1<<5) |(1<<6) |(1<<7));


DDRC &= ~((1<<0) | (1<<1) | (1<<2) | (1<<3) | // PORTC -> Inputs

(1<<4) | (1<<5) |(1<<6) |(1<<7));


DDRD &= ~((1<<0) | (1<<1) | (1<<2) | (1<<3) | // PORTD -> Inputs

(1<<4) |(1<<5) |(1<<6) |(1<<7));


// turn on PB.0..7 pullups

PORTB |= (1<<0) | (1<<1) | (1<<2) | (1<<3) |

(1<<4) | (1<<5) | (1<<6) | (1<<7);

// turn on PD0..7 pullups - PD6 skipped because LED glows faintly...

PORTD |= (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) | (1<<7);

usb_init();

while (!usb_configured());

_delay_ms(1000);

// start up PC file manager, then jumper PIND.1 low

while (PIND & (1<<1)) {}; // loop while PIND.1 High

usb_serial_flush_input(); // PIND.1 low

_delay_ms(1000);

usb_serial_write(buffer,14); // send Connect msg

usb_serial_flush_output();

while (1) { LED_ON;
_delay_ms(100);
LED_OFF;
_delay_ms(400);
}
 
Status
Not open for further replies.
Back
Top