UART Issue with PICDEM PlUS 2 board

Discussion in 'Embedded Systems and Microcontrollers' started by Neyolight, Jan 15, 2012.

  1. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Hi Everyone

    I have a PICDEM 2 Plus board with a PIC18F4620 on it. My UART code is given. The code worked perfectly fine the first time i programmed my chip but stopped working after that.

    With Hyperterminal the error is : "Unable to open COMPORT 1. Please check your port setting"

    With RealTer , the error is : Break condition received

    With Putty : Nothing happens

    I performed a loopback test on the board ( by taking our the PIC ) and Serial-to USAB adaptor and both works fine. The comport on my laptop works fine with other UART. Please guide me..I AM SUPER LOST ! :confused:

    Heres the code



    #include <p18f4620.h>
    #include <stdio.h>
    #include <delays.h>
    #include <usart.h>

    // INTIO67 configures internal oscillator
    #pragma config OSC=INTIO67, LVP=OFF, MCLRE=ON , WDT=OFF

    void setup(void)
    {
    /* Clock Setup*/
    OSCCON = 0b01110010; //select 8 MHz clock

    /* Port Set Up*/
    ADCON1 = 0b00001111; //set all pins to digital mode
    TRISD = 0x00;
    TRISA = 0x00;
    TRISB = 0b00000000;
    TRISC = 0b10000000; // RX is an input, TX is output

    // PORTBbits.RB0=1; //Turn on the 4 LEDs
    // PORTBbits.RB1=1;
    // PORTBbits.RB2=1;
    // PORTBbits.RB3=1;

    // Turn on the 4 LEDs
    // Microchip recommends writing to the PORT Latch rather than the PORT Pins
    LATBbits.LATB0=1;
    LATBbits.LATB1=1;
    LATBbits.LATB2=1;
    LATBbits.LATB3=1;


    /* Interrupt Setup */
    INTCON = 0x00; /* Clear Registers */
    PIR1 = 0x00;
    PIE1 = 0x00;
    TMR1L = 0x00;
    TMR1H = 0x00;
    T1CON = 0x00;
    RCON = 0x00;



    /* RS232 Enable */
    // OpenUSART Configures The Next Three Lines
    //RCSTA = 0b10000000;
    //TXSTA = 0b00100000;
    //BAUDCON = 0b01000000;

    // USART 9600 8-N-1
    OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 12);

    }


    #pragma code
    void main(void)
    {
    setup();

    while (1)
    {
    putrsUSART(" Hello World! ");
    // while(BusyUSART());
    Delay10KTCYx(100);

    }
    }
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Do you have a scope? Or even a logic analyzer?

    Post your schematic for your connection to the PC.
     
  3. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    I see so the board has the RS232.

    Do you have a null modem cable? Are you certain the board TX is connected to the PC RX and the board RX is connected to the PC TX?
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Not needed, I have one of these, they work handy when trying something out quick.

    Maybe the problem is the OP accidentally plugged in a Null Modem Cable?
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,607
    The problem may be more likely inside Hyperterminal then inside your PIC. If your program stopped while transmitting a serial byte then Hyperterminal scored a serial error and stopped looking at your serial stream. Just try disconnecting and reconnecting on it.

    The problem gets reported a lot when doing debugging that stops the serial unit inside the PIC, so code that runs fine doesn't work in the debugger.

    I don't use Hyperterminal for various reasons. I prefer a program called "Terminal by Br@y" which is a free download. Not pretty but good price!
     
  7. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    The exact code worked fine the first few times i tried on hyperterminal and then it stopped working for unknown reason! Im stuck on this for a month now- not sure how to get my project rolling!
     
  8. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    DO any of you see anything wrong in the code?
     
  9. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    What does this mean? :confused:
     
  10. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Do you know what a null modem cable is? It swaps TX and RX wires from one device to the other. Apparently you do not need it.

    And I will ask for a third time. For some reason you refuse to answer. Do you have an oscilloscope or logic analyzer?
     
  11. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Oh and if i take the PIC out of the board and connect the board to PC using the same serial-to-usb adaptor, IT CONNECTS!

    Does that suggest the code is at fault?
     
  12. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Oh sorry, I dont have an oscilloscope or logic analyzer but I can probably use one of my colleagues's oscilloscope if required!
     
  13. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Try to borrow it and see if you are getting an output from the Pic.
     
  14. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    How? As in what should I expect from what pin?
     
  15. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    No offense but if you don't know that then borrowing the scope is not going to do you much good. You will have a harder time learning to use it than testing your circuit.

    You should consider studying basic electronics trouble shooting if you want to participate in this hobby.

    Can your fiend help you use the scope?
     
  16. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    well thanks man--- i use to think these forums are there to support and motivate beginners - thanks for clearing that misconception!

    I know how to use the scope and if I were such an expert with these PICs and Demo Boards I wouldn't be posting questions up here!
     
  17. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Sorry but you made it sound like you have no idea what you are working with.

    Look at your datasheet for the Pic and see if you can identify the SDO pin. Place your scope probe on that pin and start your program. You should see a square wave from the SDO pin.

    Next place the probe on pin 14 of U3. You should see a square wave there.

    If that works then your MCU and software is working and it is your connection to the PC that is the problem.
     
  18. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    OK my UART IS WORKING ! Thanks all =)

    I had 2 jumpers out of place on board!
     
  19. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Nothing will replace reading the documentation or checking your work but when that fails that is were test equipment comes in handy to verify your work.

    If you can't afford a scope or a logic analyzer then at least get or build a logic probe.
    Also the PicKit II comes with a simple logic analyzer and may have helped you with this issue.

    You didn't even have to use the UART functions to help trouble shoot. You could have written a some code to toggle the pin used by the UART port and trace with your logic probe.

    I have a Zero Plus Logic Analyzer.

    http://www.zeroplus.com.tw/logic-analyzer_en/

    It is not the best analyzer on the market but is fairly inexpensive.

    It comes with protocol analyzers that will let you decode things like the UART protocol.

    A very useful tool.
     
  20. Neyolight

    Thread Starter Member

    Dec 13, 2011
    54
    3
    Allright will check it out!

    When im at uni, I have all these equipments in the lab I am in. But working outside lab is difficult with lack of such equipment to help me troubleshoot!

    Atleast I have a multimeter with me :D
     
Loading...