It is currently Mon May 20, 2013 4:15 pm

All times are UTC + 10 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Two pics communicating via UART
PostPosted: Mon Oct 18, 2010 8:16 pm 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1860
I have not had too much time lately to experiment with any projects, but this is one thing I have been looking into.

I want to create some sort of multiplayer game system where multiple pics can communicate with each other using the inbuilt UART. I have been getting some excellent help once again from the team over at http://www.digital-diy.com

Here is my test circuit:
Attachment:
SAM_0814_2.JPG
SAM_0814_2.JPG [ 74.79 KiB | Viewed 829 times ]


Basically I have two 18f4685 PICs and they are connected by two wires RX and TX on the built in UART.

The image you are seeing is drawn by sending data serially from one pic to the other. So one has the face data stored within it, it then sends the data to the receiving pic which takes care of sending the data to the LED display.

I guess this is just the start - a sort of 'proof of concept' if you will. My ultimate goal is to have two handheld game devices where you can play games such as tetris or connect four or maybe even a game of chasey based around a mario bros game map. The two game devices would connect to each other wirelessly (using the UART) and they would continually send data between each other to let each other know what they are doing. for example if we are playing connect four and player one has just had their turn, we would need to display this data on both player 1's screen and also send that data for display on player 2's screen etc...

I look forward to where this project may be headed. it may be a slow process getting there due to time constraints but we will see!

and lastly, here is the test TX code:

Code:
    Device = 18F4685
    Clock = 8                 
    Config OSC = IRCIO67         


// import library's
Include "usart.bas"

Const green_data(8) As Byte = (%11000011,%10111101,%01010110,%01111010,%01111010,%01010110,%10111101,%11000011)

Dim number As Byte
Dim x As Byte


// Start Of Program...
OSCCON = %01111111               
TRISD = %00000000
TRISA = %00000000         
number = %10101010

SetBaudrate(br115200)           

DelayMS(160)                       

While true
    For x = 0 To 7
        USART.Write("start")
        USART.WaitForStr("go")
        USART.Write(green_data(x))
        DelayMS(1)
    Next
Wend


All I am doing in the above code is transmitting the word 'start' the receiver will then wait for this word to come through, it will then acknowledge that it is ready to start by sending back the word 'go' once the transmitter has received this word, it will then start sending the first byte of data. once done, it will do it again another seven times which means the whole graphic will have been sent.


RX code:

Code:
Device = 18F4685
Clock = 8                       
Config OSC = IRCIO67   

Include "USART.bas"   
Include "SUART.bas"     
Include "utils.bas"

Dim green_data As Byte
Dim x As Byte

// Start Of Program...
OSCCON = %01111111           
TRISD = %00000000
PORTD = %00000000           
TRISA = %00000000
PORTA = %00000000             
TRISB = %00000000
PORTB = %00000000           
TRISE = %00000000
PORTE = %00000000                   

SetBaudrate(br115200)

DelayMS(150)                         

PORTA = %00000000
PORTE = %00000000

While true
    For x = 0 To 7
        USART.WaitForStr("start")
        USART.Write("go")
        USART.Read(green_data)
        PORTB = green_data
        If x < 6 Then
            PORTA.bits(x) = 1
        ElseIf x = 6 Then
            PORTE.bits(0) = 1
        ElseIf x = 7 Then
            PORTE.bits(1) = 1
        EndIf
        DelayMS(1)
        PORTA = 0
        PORTE = 0
    Next
Wend


This receiver piece of code receives the graphic data and then takes care of drawing it on the display. It waits for the start string to come through, it then sends out the go string and then receives the data that is to follow (one byte at a time) it then sends this byte to the LED cathodes. We then need to activate one row of anodes so I have these connected to PORTA and the last two to PORTE. It will do this a total of eight times which means the full graphic will then be drawn.


Top
 Profile  
 
 Post subject: Re: Two pics communicating via UART
PostPosted: Sun May 15, 2011 9:41 pm 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
I just learnt something from this Brad, I didnt know that you could use usart to wait for a String command in this way. :)

Code:
{
****************************************************************************
* Name    : WaitForStr                                                     *
* Purpose : Wait for a string to be received                               *
****************************************************************************
}
Public Sub WaitForStr(pStr As String)
   Dim Index As Byte

   ClearOverrun
   Index = 0
   While pStr(Index) <> null
      If WaitFor(pStr(Index)) Then
         Inc(Index)
      Else
         Index = 0
      EndIf
   Wend
End Sub


Top
 Profile  
 
 Post subject: Re: Two pics communicating via UART
PostPosted: Mon May 16, 2011 10:02 am 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1860
Glad it helped!


Top
 Profile  
 
 Post subject: Re: Two pics communicating via UART
PostPosted: Tue Aug 14, 2012 12:18 pm 
Offline
I practically live here!
I practically live here!
User avatar

Joined: Mon Aug 13, 2012 4:23 am
Posts: 171
Location: Sarasota, Florida
How did this project end up? Did you reach any breakthroughs? Is it too much for the microprocessor to output at high speed and receive data from another microprocessor at a fast speed?

_________________
Joshua


Top
 Profile E-mail  
 
 Post subject: Re: Two pics communicating via UART
PostPosted: Sat Aug 18, 2012 9:57 am 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1860
To be honest, I think I left this project for another and didn't ever get back to it!

So many projects - so little time!


Top
 Profile  
 
 Post subject: Re: Two pics communicating via UART
PostPosted: Sat Aug 18, 2012 2:43 pm 
Offline
I practically live here!
I practically live here!
User avatar

Joined: Mon Aug 13, 2012 4:23 am
Posts: 171
Location: Sarasota, Florida
I know what you mean... too many things, too little time...

_________________
Joshua


Top
 Profile E-mail  
 
 Post subject: Re: Two pics communicating via UART
PostPosted: Sun Aug 19, 2012 1:06 pm 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1860
Saimaster13 wrote:
I know what you mean... too many things, too little time...


That's right!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 10 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme made by Keenen Wheeler