PIC stuck in allways HIGH Out.

AlbertHall

Joined Jun 4, 2014
12,347
You are still not clearing RCIF in the interrupt routine. If this interrupt ever happens it will run the interrupt code continuously and never get to the rest of the code.
 

AlbertHall

Joined Jun 4, 2014
12,347
Your latest code toggles those three pins when run in the simulator.
Try putting a breakpoint on one of the lines which should those pins and if the breakpoint is never hit then work out why. Single step through the code may help.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Stepping in code, and all is correct, the PORTB pins gets high, but never low again,.
Is it due to i use RB0=0; in port C and D i use ex PORTC=0b10000000;

Have tried to isolate and just using RB0 RB1 RB2 one at a time,
Allways stuck in HIGH, If all 3 is used i get sometime a square signal on RB0,
RB5 seems to work correct. but this one is not conneced same way as the other 3 outputs.
Check schematic, .
Testet with Diodes and without diodes. same problem.
 

AlbertHall

Joined Jun 4, 2014
12,347
Aha. That suggests that you have something on portb pins which restricts the voltage on the pins then you hit the 'read-modify-write' problem and explains why it works correctly in the simulator.
 

upand_at_them

Joined May 15, 2010
940
Been following, but since I don't do much in C it didn't stand out at first. Always use LAT? for outputs and PORT? for inputs when possible. Some older devices only have PORT? so you're stuck with that route.
Use LAT for writing, use PORT for reading. For PIC's that don't have LAT, you should use a shadow register and write that full byte value to PORT.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Problems understanding USART,
I transmit data 80 00 01 05 81. like this.

Code:
  EUSART1_Write(80); // to indicate it's ex time we are sending.
     __delay_ms(100);
  EUSART1_Write(hour); // send the Hour // integer
   __delay_ms(100);
  EUSART1_Write(minut); // send minutes // integer
   __delay_ms(100);
     EUSART1_Write(second); //send seconds // integer.
   __delay_ms(100);
     EUSART1_Write(81); // to indicate we have no more.
   __delay_ms(100);
This way i get a small delay in transmission, but have also tried without the delays.
my send command is like this
Code:
void EUSART1_Write(uint8_t txData)
{   
     while(0 == PIR3bits.TX1IF)
    {
    }

        TX1REG = txData;
    
}
All works fine, when connected to interface to PC.
But when recieving MCU, is goes bad.
The "interrupt" happens like it should, the decoding of data is the problem.
Here is interrupts code.
Code:
void __interrupt() myISR(void)
{// things to do
    // only interrupt is from RX EUSART
    if (RCIF==1)
   {
   CREN=0;
   UART_Buffer=RCREG;
    RB4=!RB4; // test only.
   DataRecieve=1;
   CREN=1;
   }
}
RB4 is flashing, so i know that data is comming,


As my "main" code takes 6.6 ms to run, i think i have time enough to process the "data" before next interrupts. around 100 ms, as the delay is.
Problem is, is data in HEX or what format ?
I main code i check for UART_Buffer==80 or UART_Buffer==0x80
UASRT.PNG
can i not do what i do, or do i wait until both characters is recieved or how ?
Works ok, when i transmit from BlueTooth to MCU, also via UART.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
that i have difficult to see, i have tried to determen it, but dont know how,.
Have just LED connected no LCD.
Have tried " if RCREG == xx , then do something, ect.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
the "master" mcu is connected to "slave" mcu, not to computer,
i can monitor the data by use of UART tool from PICKIT2 and also by Scope.
Maybe i could "store" the data in EEPROM and then read it out.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
that give me a big 00. under my test i just send hex 50.
Did also save a "know" value in another EE. and that value did come up Ok.
Code:
void __interrupt() myISR(void)
{// things to do
    // only interrupt is from RX EUSART
    if (RCIF==1)
   {
   CREN=0;
    
   eeprom_write(0,RCREG);
   eeprom_write(1,44);// 2C Hex , Control value.
    RB4=!RB4; // LED Did flash.
      CREN=1;
 
  
  }
}
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
702
Get FERR and NO OERR,
Do i need to send a Break char, ? TX1REG="\0" or ?

In test here i use PICKIT2 UArt tool, cant send break ?
 
Top