Serin serout problem


Closed Thread
Results 1 to 40 of 337

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I meant are you putting the transmit code into the transmit PIC and the receive code into the receive PIC, not the whole thing into both PICs...


    'TRANSMIT PIC = one pic

    'RECEIVE PIC = another pic
    dont worry, only the part that belongs there

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I meant are you putting the transmit code into the transmit PIC and the receive code into the receive PIC, not the whole thing into both PICs...


    'TRANSMIT PIC = one pic

    'RECEIVE PIC = another pic
    dont worry, only the part that belongs there
    Ok, just checking because in that one picture it looked like both PICs had the same writing on them.

    Now try this code:


    'RECEIVE PIC

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250

    'try1 = count of times waiting for data, try2 = count of bytes received
    try1 var byte : try2 var byte : temp var word : tempf var word
    temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
    input portb.2 : pause 2500
    try1 = 0 : try2 = 0

    loop:
    lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
    try1 = try1 + 1 : temp = 0 : tempf = 0
    serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
    temp.highbyte = temp1 : temp.lowbyte = temp2 : tempf.highbyte = temp3 : tempf.lowbyte = temp4
    if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
    lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
    lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
    lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FR" : pause 100
    lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
    goto loop
    End











    'TRANSMIT PIC

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 16667

    try1 var byte : try2 var byte : output portb.2 : input portb.3
    dq var portb.4 : temp var word : tempf var word
    temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
    pause 2500
    try1 = 0 : try2 = 0

    loop:
    try1 = try1 + 1
    lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2
    owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
    owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
    owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
    tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32

    tempf = 444 'hardcode transmitter to have 444 in tempf space
    temp = 888 'hardcode transmitter to have 888 in temp space
    lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
    lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FT"
    lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
    temp1 = temp.highbyte : temp2 = temp.lowbyte
    serout portb.2 , t2400 , [ temp1 , temp2 ]
    temp3 = tempf.highbyte : temp4 = tempf.lowbyte
    serout portb.2 , t2400 , [ temp3 , temp4 ]
    try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
    goto loop



    And post a fresh picture if you can
    Last edited by skimask; - 24th December 2006 at 08:36.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ok , I'm back, still no changes,
    picture up
    The two leds there are from a previous program which instead of using lcdout, I was trying to make led blink.
    but the picture was takien while your last program was working
    Last edited by lerameur; - 24th December 2006 at 13:28.

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    i tried this program for the reciver. The led blinks, If I added the serin , led would sit on high. There is definately a problem with serin command, It does not work with lcdout or simple led blinking

    'RECEIVE PIC

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250

    'try1 = count of times waiting for data, try2 = count of bytes received
    try1 var byte : try2 var byte : temp var word : tempf var word
    temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
    input portb.2 : pause 2500
    try1 = 0 : try2 = 0
    trisb=%00000000
    loop:
    lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
    try1 = try1 + 1 : temp = 0 : tempf = 0
    'serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
    Portb.4 =1 : pause 500 : portb.4=0
    Portb.3 =1 : pause 500 : portb.3=0
    goto loop
    End


    I also wanted to see if the chip was able to see the data coming in, so i tried this loop, and nothing is happening to the led:

    loop:
    serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
    if temp1 > 0 then
    Portb.4 =1 : pause 500 : portb.4=0
    Portb.3 =1 : pause 500 : portb.3=0
    endif

    goto loop
    End
    Last edited by lerameur; - 24th December 2006 at 14:08.

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Ok now I used your pogram and changed the serin line :

    serin portB.2 , t2400 , temp1 -----works

    It takes in the value,IT is NOW working. BUT For some odd reason it do not take multiple input..

    serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ] ------------- do not work

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default methinks

    Quote Originally Posted by lerameur View Post
    Ok now I used your pogram and changed the serin line :

    serin portB.2 , t2400 , temp1 -----works

    It takes in the value,IT is NOW working. BUT For some odd reason it do not take multiple input..

    serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ] ------------- do not work
    Hi leramuer.
    I think you need to store and retrieve those values in an array. I am not experienced enough to have confidence with this statement, but methinks it is so.
    Anyone, ring in here with an opinion!
    JS
    edit:
    try this
    Temp var byte[4]
    Temp[0] = n ' your first temp value
    Temp[1] = n1 ' your second value
    Temp[2] = n2 ' your third value
    Temp[3] = n3 ' your fourth value
    serout portB.2 , t2400,[# temp[0],# temp[1], # Temp[2], # Temp[3]]
    it displays on my backpack display.
    JS
    Last edited by Archangel; - 25th December 2006 at 07:56. Reason: add possible solution

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Merry Christmas to all

    I just tried that , the information is not sending. Maybe I got the code wrong, but it till skipping over the lcdout

    k

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    Ok now I used your pogram and changed the serin line :

    serin portB.2 , t2400 , temp1 -----works

    It takes in the value,IT is NOW working. BUT For some odd reason it do not take multiple input..

    serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ] ------------- do not work


    Ok, I'm back. In the last program I posted, I had the values hardcoded in the transmitter side, so since they displayed correctly, now try a couple of dummy values hardcoded in the receiver side. Try out these programs and let me know what happens....

    Things I changed since the last programs posted a couple of days ago:

    Removed the hardcoded '444' and '888' on the transmitter side

    Added a hardcoded '444' and '888' on the receiver side.

    On both the transmit and receive side, I split the serout and serin into 4 seperate lines, each sending (or receiving) one byte. I don't know if this will fix the problem or not.

    I also added a couple of lines in there to 'sync' up the transmit and receive sides in the case that the receive side starts receiving in the middle of a transmission (which could happen). Very simple setup - 6 bytes are sent, 1st byte - $aa , 2nd-3rd-tempC, 4th-5th-tempF, 6th byte-$55. 1st and 6th byte should add up to $FF. If it doesn't, it was received in the wrong order is values are thrown out. (actually, the 2 numbers from the transmit side could be any pair, as long as they add up to $ff, the receiver will take it, which could mess up the values at the receiver if the right temperature combination comes along, but we'll stay with this for now)

    If the receive side shows '444' and '888', remove the lines and comments, and try it again. It just might work...

    Of course then again, over the past couple of days, you might've gotten it fixed, which would be a sweet deal overall...

    Added a line to idle the transmit line high between characters. This might fix the whole problem...?(see next post)

    'RECEIVE PIC

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250

    'try1 = count of times waiting for data, try2 = count of bytes received
    try1 var byte : try2 var byte : temp var word : tempf var word
    temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
    leader var byte : trailer var byte
    input portb.2 : pause 2500
    try1 = 0 : try2 = 0

    loop:
    lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
    temp = 0 : tempf = 0 : leader = 0 : trailer = 0 'clear out old values
    temp1 = 0 : temp2 = 0 : temp3 = 0 : temp4 = 0 'clear out old values
    serin portb.2 , t2400 , [ leader ] 'get leader byte
    serin portb.2 , t2400 , [ temp1 ]:serin portb.2 , t2400 , [ temp2 ] 'get data
    serin portb.2 , t2400 , [ temp3 ]:serin portb.2 , t2400 , [ temp4 ] 'get data
    serin portb.2 , t2400 , [ trailer ] 'get trailer byte

    'remove the line below if 444 and 888 show up on the LCD
    temp1 = 1 : temp2 = 188 : temp3 = 3 : temp4 = 120
    'remove the line above if 444 and 888 show up on the LCD

    if ( leader + trailer ) <> $ff then 'if leader + trailer doesn't add up right...
    lcdout $fe , $c0 , "No Sync..", DEC3 try1 , "," , DEC3 try2
    pause 200 : goto loop 'try again
    endif

    temp.highbyte = temp1 : temp.lowbyte = temp2 'put the received values
    tempf.highbyte = temp3 : tempf.lowbyte = temp4 'where they need to be
    if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
    lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
    lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
    lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FR" : pause 100
    lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
    goto loop
    End











    'TRANSMIT PIC

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 33333

    try1 var byte : try2 var byte : output portb.2 : high portb.2 : input portb.3
    dq var portb.4 : temp var word : tempf var word
    temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
    pause 2500
    try1 = 0 : try2 = 0

    loop:
    lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
    owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
    owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
    owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
    tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
    lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
    lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FT"
    lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
    high portb.2 : serout portb.2, t2400 , [ $aa ] 'send a leader byte
    temp1 = temp.highbyte : temp2 = temp.lowbyte
    high portb.2 : serout portb.2 , t2400 , [ temp1 ]
    high portb.2 : serout portb.2 , t2400 , [ temp2 ] 'send data
    temp3 = tempf.highbyte : temp4 = tempf.lowbyte
    high portb.2 : serout portb.2 , t2400 , [ temp3 ]
    high portb.2 : serout portb.2 , t2400 , [ temp4 ] 'send data
    high portb.2 : serout portb.2 , t2400 , [ $ff ] 'send a trailer byte
    high portb.2 : try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
    goto loop
    Last edited by skimask; - 26th December 2006 at 14:17. Reason: increase char_pacing value in transmit section and added lines to idle portb.2 high

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Serin problems

    Something else I just found...
    http://www.picbasic.co.uk/forum/show...ght=idle+state

    You might have to add a bit of code to manually toggle the pin before/after transmitting...not sure... I'll look into it more tomorrow. This may have been the problem I was having before (long time ago) when I switched over to using the actual PIC hardware serial modules.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  3. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 19:44
  4. Replies: 11
    Last Post: - 13th July 2005, 19:26
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

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