DrBudz
Junior Member level 3
I'm trying to send character via UART, but I get some other character.
There is probably an error because of the wrong INTOSC setup, which is causing wrong baud rate.
Everytime I change settings of INTOSC, I get a different charcter on UART TX.
Correct baud rate is selected in uart terminal (9600 in this case, data bits 8, parity-none, no handshaking, 1 stop bit)
PIC MCU is 18F46K20.
Configuration is set for INTOSC - RA6 and RA7 as I/O, and freq in project is set to 32MHZ.
When I measure the delay time, it seems to be 2sec, which is OK because there is 2 delays with 1000ms.
It could mean that the OSC is working correctly and that there could be a problem with something else....
Can somebody try this code or tell me what am I doing wrong?
Thanks!
There is probably an error because of the wrong INTOSC setup, which is causing wrong baud rate.
Everytime I change settings of INTOSC, I get a different charcter on UART TX.
Correct baud rate is selected in uart terminal (9600 in this case, data bits 8, parity-none, no handshaking, 1 stop bit)
PIC MCU is 18F46K20.
Configuration is set for INTOSC - RA6 and RA7 as I/O, and freq in project is set to 32MHZ.
Code:
void main() {
OSCCON=0b01100000; //Internal OSC 8MHz
PLLEN_bit=1; //PLL enabled - osc=4x8MHz =32MHz
PORTA = 0 ;
TRISA = 0xff ; // set PORTA as input for ADC
PORTB = 0 ;
TRISB = 0xff ; // set PORTB as input for buttons
LATD = 0 ;
TRISD = 0 ; // set PORTD as output
SLRCON = 0; // Set output slew rate on all ports at standard rate
INTCON.GIE=1; //global interrupts enabled
INTCON.PEIE=1; //periferni interapti dozvoljeni
PIE1.RCIE=1;
TRISC=0x00; //desperate attempt to find a possible cause
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while(1){
UART1_Write('X');
Delay_ms(1000);
LATD=0;
Delay_ms(1000);
}
}
When I measure the delay time, it seems to be 2sec, which is OK because there is 2 delays with 1000ms.
It could mean that the OSC is working correctly and that there could be a problem with something else....
Can somebody try this code or tell me what am I doing wrong?
Thanks!