Two pics communicating via UART

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Two pics communicating via UART

Post by brad » Mon Oct 18, 2010 8:16 pm

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:
SAM_0814_2.JPG
SAM_0814_2.JPG (74.79 KiB) Viewed 11245 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: Select all

    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: Select all

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.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Two pics communicating via UART

Post by bitfogav » Sun May 15, 2011 9:41 pm

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: Select all

{
****************************************************************************
* 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

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Two pics communicating via UART

Post by brad » Mon May 16, 2011 10:02 am

Glad it helped!

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Two pics communicating via UART

Post by Saimaster13 » Tue Aug 14, 2012 12:18 pm

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

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Two pics communicating via UART

Post by brad » Sat Aug 18, 2012 9:57 am

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!

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Two pics communicating via UART

Post by Saimaster13 » Sat Aug 18, 2012 2:43 pm

I know what you mean... too many things, too little time...
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Two pics communicating via UART

Post by brad » Sun Aug 19, 2012 1:06 pm

Saimaster13 wrote:I know what you mean... too many things, too little time...
That's right!

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: Google [Bot] and 16 guests