On 3 Apr 2008 at 18:06, piclist@ian.org wrote: > I am trying to send data out on the hardware USART of a PIC18F252 from > readign the datasheet and it is not sending any data. > > I have the output pin on scope and when I run the init code it goes high, > but when I try to send chartacters, nothing happens. > > Here is the bit of code I am using. (BoostC compiler) > > trisc.6 = 0; // Set TX pin for output. > trisc.7 = 1; // Set RX pin for input. > spbrg = 51; // 9600 baud at 20MHz clock. > txsta.BRGH = 1; // 1 = High baud rate. > txsta.SYNC = 0; // 0 = async. > rcsta.SPEN = 1; // 1 = Enable the serial port hardware. > txsta.TX9 = 0; // 0 = No 9th bit. > txsta.TXEN = 1; // 1 = Enable transmission. > > while (1) > { > while (!txsta.TRMT) > txreg = 'H'; > while (!txsta.TRMT) > txreg = 'i'; > > porta.1 = !porta.1; > } > > The led blinks (I can see it on the scope) but the TX pin (pin RC6/TX/CK) > just stays high and does nothing at all. > > I assume I don't need to tie the TX pin to ground or voltage? I am going > to another PIC so I don't need to do any RS232 level inversion either. > > Any clues? Thanks again! Hi Ian, Your while loops look wrong. Do you really want to continuously write to txreg until the trmt bit goes high? Here's a snippet from one of my projects, was for a 16F device but should give you some clues... TXREG = x; // Put the byte into TXREG while(!TXIF); // Wait for transfer to TSR while(!TRMT); // Wait for it to be sent -- Brent Brown, Electronic Design Solutions 16 English Street, St Andrews, Hamilton 3200, New Zealand Ph: +64 7 849 0069 Fax: +64 7 849 0071 Cell: +64 27 433 4069 eMail: brent.brown@clear.net.nz -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist