Phil, Thanks for the help. I checked into the header files and learned a little more on what it was trying to do. Did not help my issue, but it did teach me a little bit. My problem was a bad cable, all this time ..... Phil wrote: I assume port B has some LEDs so that's how you know you dont get there. Try doing a readUSART at the end of init to clear the first "interrupt" You should probably take a look at what DataRdyUSART() is doing. I assume its a "macro" (inline asm looking at the TX bit, no doubt) in usart.h Then look at the data sheet on how the usart knows that its ok to receive a new character. Phil --- In p...@yahoogroups.com, "Travis L. F Bailey" <tbailey@l...> wrote:Help, I am missing some obvious mistake. I just don't see it. I am using a pic18f452 chip and a max232 chip to communicate to my laptop's serial port. I can send data from the pic to the pc,but, Ican not receive data from hyperterm to the pic chip. I am alsoconnectedto a ds1620 digital thermometer (That bit works fine). I have attached the MPLAB c18 c code that I am using. Let me knowifyou see the error. It is driving me crazy, Thanks, Travis CODE ****** #include <p18f452.h> /* for TRISB and PORTB declarations */ #include <delays.h> #include <usart.h> #include <stdlib.h> /* Port Defines */ #define RST PORTDbits.RD0 #define CLK PORTDbits.RD1 #define DQ PORTDbits.RD2 /*ds1620 Functions */ unsigned char write_config = 0x0c; unsigned char start_conv = 0xee; unsigned char read_temp = 0xaa; unsigned char DQin = 4; unsigned char DQout = 0; void write_ds1620_bit (unsigned char b) /* This function sends a data bit to DS1620 */ { DQ = b; CLK = 0; CLK = 1; DQ = 1; } unsigned char read_ds1620_bit() /*Reads a data bit */ { unsigned char b; TRISD = DQin; CLK = 0; b = DQ; CLK = 1; TRISD = DQout; return (b); } void write_to_ds1620(unsigned char ds1620_function, unsigned char ds1620_data, unsigned char bit_count) /* This function writes data/config to ds1620 */ { unsigned char i, this_bit; RST = 1; /* Send function */ for (i=0;i<8;i++) { this_bit = ds1620_function >> i; this_bit = this_bit & 0x01; write_ds1620_bit(this_bit); } /* Send data */ for (i=0;i<bit_count;i++) { this_bit = ds1620_data >> i; this_bit = this_bit & 0x01; write_ds1620_bit(this_bit); } RST = 0; } unsigned int read_from_ds1620 (unsigned char ds1620_function,unsignedchar bit_count) /*Reads data, conf from ds1620 */ { unsigned char i, this_bit; unsigned int ds1620_data; ds1620_data = 0; RST = 1; /*send function */ for (i=0;i<8;i++) { this_bit = ds1620_function >> i; this_bit = this_bit & 0x01; write_ds1620_bit(this_bit); } /*read data */ for (i=0;i<bit_count;i++) { ds1620_data = ds1620_data | read_ds1620_bit() << i; } RST = 0; return (ds1620_data); } void main (void) { char temperature[4]; char triscout[4]; unsigned int temp; unsigned long temp2; int shorttime; int longtime; int counter; char data; TRISB = 0; /* configure PORTB for output, LED Bank */ LATB = 0; shorttime = 5; /* Delay for loop */ longtime = 1000; /* Longer Delay for loop */ TRISD = DQout; /* For ds1620 start */ LATC = 0; TRISC = 0b10111111; OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 25); /*config ds1620 for continous operation */ write_to_ds1620(write_config,2,8); Delay10KTCYx(longtime); /* start conversion */ write_to_ds1620(start_conv,0,0); Delay10KTCYx(longtime); PORTB = 1; data = 0; while (1) { if (DataRdyUSART()) { /****************************** Problem is in here. I never get here, never see input *******************************/ data = ReadUSART(); putrsUSART ("Input: "); WriteUSART ( data ); putrsUSART (" \r\n"); PORTB = 24; Delay10KTCYx(longtime); PORTB = 0; Delay10KTCYx(longtime); } /* Start temp grab and convert */ temp = 0; temp2 = 0; temp = read_from_ds1620(read_temp,9); temp2 = temp / 2; temp2 = temp2 * 1.8; temp2 = temp2 + 32; /* Output temp and other in put to screen */ ultoa(temp2,temperature); putrsUSART (" Temperature: " ); putsUSART ( &temperature ); putrsUSART (" F \r\n"); itoa(temp,temperature); putrsUSART (" Temperature: " ); putsUSART ( &temperature ); putrsUSART (" C \r\n"); itoa(TRISC,triscout); putrsUSART (" TRISCOUT: "); putsUSART ( &triscout ); putrsUSART (" \r\n"); putrsUSART (" Data Input: "); putsUSART ( &data ); putrsUSART (" \r\n"); putrsUSART (" \r\n"); /* Show raw temp on LED bank */ PORTB = temp; Delay10KTCYx(longtime); Delay10KTCYx(longtime); } } ***************************** Sample Output Temperature: 73 F Temperature: 47 C TRISCOUT: 191 Data Input: Temperature: 73 F Temperature: 47 C TRISCOUT: 191 Data Input: Temperature: 73 F Temperature: 47 C TRISCOUT: 191 Data Input:to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |