HELP! Serial input between Pic and PC (urgent)


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The first thing that I see is you have SERIN and SEROUT on the same pin.
    Code:
    SERIN PORTA.3,
    
    SEROUT PORTA.3,
    I have never tried A4 for serial
    http://www.picbasic.co.uk/forum/showthread.php?t=562
    You may have to use another pin.

    Right now do not worry about TRISA. The SERIN/SEROUT takes care of that.
    Dave
    Always wear safety glasses while programming.

  2. #2
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default

    If you just want the short answer.....

    I think you may have made a misstake with the pins
    PORTA.3 is Data PIC>>>>PC (serout in pbp)
    PORTA.4 is Data PC>>>>PIC (serin in pbp)
    using PORTA.4 as an input is not a problem at all, if you want to use it as output you need a pull-up resistor to make it work.
    Change is your sw and it might work better.

    If you want a longer answer......
    Yes datasheet can be really strange to read and understand, this we all have to accept. Training and experience will make it easier and even simple. This is fact.

    Now to a different thing, making electronics with PIC inside is not that different from sport, training makes a difference and not all people have the same skills. It is easy to wish for a cool electronic gadget but much harder to make it. I am not writing this to put someone down, no I am writing this to explain how to get there and that is One Small Step at the Time. Don't expect to write a missileguiding SW the first day but eventually you will.

    So I want to make a thing that can turn on and off LED from a PC, how would I do that?

    A, Make a plan, with a good plan you will save much time later. Figure out what you want the circuit to do and what hardware you will need. You can always make the plan better later but you honestly need a plan before you start.

    B, Test the hardware. Here is the best thing the undervalued Flash a LED program most usefull. Time spent verifying the hardware you will get back 1000 times later because when you see strange things you can rule out HW problems. If you can't flash a led you can not expect anything else to work ever....

    C, If you want to connect to a PC do not start with a SERIN problem. Start with a SEROUT so you can see that you can send data to the PC. Even if you will not use it later?? YES!! Because it is easier to recieve data with a PC compared with a PIC, if you can send data to the PC it is more likely that the other way is working also. I almost always include a line early in the program to send SEROUT......... " PIC STARTED " so when I see this is hyperterminal I understand that the PIC is happy. It is also a great way of troubleshooting later because you can always send serial data to the PC to display arrays and other variables. When you can see the data on the PC you have proof that Baud and Mode are correct and you also know you are using the correct serial port on the PC.

    D, Make sure you know where the PIC is in your progam before you do a Serin. Like other people said before use a start char to start the Serin function for example ":" or "X" or any other you want to use, just make sure you use one.... so do a serout first in your code
    Serout............"PIC waiting for data" followed by a SERIN ........... that has a start char. Now you are sure that the PIC is waiting for char from the PC, now use the PC to send 2 char (start char + data char). After the Serin line I would put a new Serout line that has Serout.......... "Data recieved",#Data_Char Now I can see that the PIC moved forward in the program and what data was recieved. Please remember that ASCII and dec numbers can be confusing so double check or force the data to be in DEC fromat using the # function. IF you are not using a start char you are not sure that the data char is correct, serin will take any data and you will be in the land of trouble.

    This is one small step at the time, the key to R&D and the best way to make progress. Later when you have everything working you can remove lines in the code that you are not using and the code becomes smaller and cleaner.

    The good thing with PIC is that they are small computers, they do exactly what you tell them, the bad thing with them is they are small computers, they do exactly what you tell them. You can not expect the PIC to be forgiving in anyway, there are no help files incuded just the data sheet written by nerds for nerds.

    To make the a circuit that turns on a LED is a very good project but it is not a simple project, it will take time, skill and patience but eventually you will get it to work.

    Define OSC 10
    include "Modedefs.bas"
    ADCON1 = 7

    TRISA = %010000 'RA4 as serial input, RA3 as serial output
    TRISB = 0 'PortB used to ON the LED

    CHAR var byte
    PORTA.3=1
    PORTB = 0
    SEROUT PORTA.3,T9600,[" PIC started",10,13] 'I used hyperterminal to received the data
    GOTO MAIN


    PC_IN:
    SEROUT PORTA.3,T9600,["Use : as start char",10,13] ' write :A in hyperteminal...
    SERIN PORTA.4,T9600,[":"],CHAR
    SEROUT PORTA.3,T9600,["Data from PC ",CHAR,10,13] '
    RETURN

    Main:
    GOSUB PC_IN

    GOTO MAIN




    GOTO MAIN

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    And after all that, I still cannot understand why you don't use the USART of the PIC? Are you going to use those pin to connect something else?

    Ioannis

  4. #4
    Join Date
    Nov 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hi sinoteq,

    Thanks for your advice, I will try this.

    Hi Ioannis,

    Yes, I was using the PORTC to do another function.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    If you can reassign the port pins, I strongly suggest to do so. The gain is enormous in processing speed/power.

    Ioannis

  6. #6
    Join Date
    Nov 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Hi all,

    Finally my program can work already. So, thank you to those people that helping me to solve this problem exspecially Mr. Ioannis, sinoteq and Mister e. Thank you very much

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    It would be nice to post the solutions that made it work.

    Ioannis

Similar Threads

  1. Send binary file to pic over pc serial port
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 3rd May 2011, 13:47
  2. Replies: 11
    Last Post: - 12th July 2008, 02:36
  3. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35
  4. High Speed Serial Comm PC - PIC and PIC - PIC
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 16th January 2007, 21:55
  5. Replies: 5
    Last Post: - 20th March 2006, 01:34

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts