Serial communication problem


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78

    Post Serial communication problem

    I am trying to send 8 bits of data out at each rise in the clock cycle. PIN RC5 is where I am sending the data from serially in the PIC16C63A, and PIN RC3 is my synchronous clock but I am getting very confused.

    my goal is to mimic the SPI but not sure if I am doing that here. the confusion comes where I am trying to send the variable slug1 serially (one bit at a time). can anyone help
    me with this. I am quite new to programming the PIC.

    Here is what I have so far.

    INCLUDE "modedefs.bas"

    i VAR BYTE
    Flag1 VAR BYTE
    Flag2 VAR BYTE
    Count_send VAR BYTE
    slug1 VAR WORD

    slug1 =10110111
    clock = 0
    char array[8]
    TRISC =%00010000

    start:
    Flag1 = 0 /*Portc pin 1*/
    While(Flag1 == 0)
    Flag2 = 1 /*PortC pin 2*/

    Count_send = 0
    Count_send = Count_send + 1

    if(Count_send == 1) then

    count = 0
    PORTB.3 = 0
    for (count1 =0; count1 <8; count1++) ; loop 8 time for each bit
    {
    PORTC.3 = 1 ; clock = 1
    goto SEND1 ; send a char
    PORTC.3 = 0 ; clock = 0
    }

    if(count = 8)
    array[8] = 0

    if(Count_send == 1) then
    Flag1 = 1
    endif

    Flag2 = 0
    Pause 100
    Flag1 = 0
    Flag2 = 1
    wend

    SEND1:

    SerOut PORTC.6, T2400, array[count]
    count = count + 1
    endif
    return
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Srigopal,

    First off... have you scoped the output pin?? and the Clock Pin?

    Second.. if you have, and your data looks correct on your scope, maybe it is your receiver instead.

    Also If I remember correctly Serout sends in 8 bit data.

    That means if you want to send a bit by bit situation... you must first isolate and tell whether the Bit is a one or a zero... then add 48 to it to convert it to a 8 bit byte... then send it.

    Bit var byte

    For s=0 to 7
    Bit=Data.s
    Bit=Bit+48
    Serout(Pin,T2400,Bit)
    Next s

    (Or something in this nature).

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello

    First a couple of things on your program...

    Bit is a Reserve word. You will have to use something other than Bit... I used Bit as a example of how the program will work.

    Second. I do not know how you want your ""Slug" sent.

    By each individual bit? or all together... I gave you a example of sending it each individual byte.

    you can send it all together by changing your Slug value and putting a "%" in front of it... Then send the whole thing. as a 8 byte data. (But you leave off adding the 48).


    Thus your program will look something like.

    bytetosend Var byte



    Slug="%01101101
    bytetosend=Slub 'this is redundant...but ....
    Serout Pin,T2400,bytetosend


    Receive is

    bytetoreceive var byte
    counter var byte

    Serin Pin,T2400,bytetoreceive

    'lets do something with each bit.
    for counter=0 to 7 step 1
    bytetoreceive.counter 'each individual bit
    next counter
    Last edited by Dwayne; - 19th July 2004 at 14:39.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

Similar Threads

  1. Replies: 18
    Last Post: - 4th July 2017, 14:26
  2. serial communication problem
    By kindaichi in forum Serial
    Replies: 13
    Last Post: - 11th March 2010, 16:37
  3. Replies: 5
    Last Post: - 20th March 2006, 01:34
  4. Serial Communication Problem
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 23rd February 2006, 02:11
  5. Replies: 8
    Last Post: - 11th November 2004, 20:08

Members who have read this thread : 1

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