High Speed Serial Comm PC - PIC and PIC - PIC


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Start using Interrupts if you haven't done yet.

    Hi Manuel,

    Whenever a byte is received by the USART it is made available in the receive buffer while the other byte (2byte buffer) still gets stuffed. You must read the byte before your another byte is full. If not, your USART faces a buffer underrun condition and an error is raised.

    The USART supports interrupts and it is fired as soon as a byte is ready. You might be in middle of something but still can grab the data in your own buffer and resume. Later you can check for newly available data and modify your display. If you are doing multiplexing then you might be needing interrupts anyway to get good timings and display stabilty.

    It is better if you have some sort of hardware block diagram.
    Regards

    Sougata

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Whenever a byte is received by the USART it is made available in the receive buffer while the other byte (2byte buffer) still gets stuffed. You must read the byte before your another byte is full. If not, your USART faces a buffer underrun condition and an error is raised.
    I don't mean to be picky here but the 'buffer' is actually two bytes so a third byte can be 'on its way in' without buffer over run. As soon as the third byte is clocked in, though, you'll get a buffer over run error.

    There's a document on the Microchip website called Usart.pdf (no document number or anything) that explains the operation in asynchronous mode. The following is an extract from it:
    The use of a separate receive shift register and a FIFO buffer allows time for the software running on the PICmicro MCU to read out the received data before an overrun error occurs. It is possible to have received two bytes and be busy receiving a third byte before the data in the RCREG register is read.
    Hope it helps.

    /Henrik Olsson.

  3. #3
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Hi. Thanks once again for all your help!!! With all the info you gave me, I was able to compile some program to transfer 8 bytes using USART, to another PIC and perform PWM to them (not multiplexing yet)
    I have not been able to try the code out yet, because I do not have two 16F877A right now. Anyway here are the TX and RX codes. Im sure they have quite a lot of errors, but a start is a start, isnt it??
    (Please check also the regs at the beginning, I wasnt sure of some bits...

    This is the TX code:

    DEVICE 16F877A
    ALL_DIGITAL = TRUE
    XTAL = 20

    DIM PWMDATA[8] AS BYTE 'VARIABLES FOR DATA TRANSMISSION

    'LOAD PWMDATA FROM SOMEWHERE ELSE...

    DIM INDEX AS BYTE 'INDEX FOR DATA RECEPTION FOR PWMDATA
    DIM X AS BYTE

    TXSTA = %00100110 'ASYNCHRONUS, HIGH SPEED, TRANSMISSION ENABLED.
    RCSTA = %10010000 'USART ON, 8-BIT, NO ADRESS DETECTION, CONTINOUS RECEIVE
    SPBRG = %00001010 'SET BAUDSPEED TO 113200 (HOW DO YOU CALCULATE THE ERROR?)

    MAIN:
    FOR INDEX = 0 TO 7
    TXREG = PWMDATA[INDEX]
    WHILE TXIF = 0 : WEND
    NEXT INDEX
    GOTO MAIN

    /////////////////////////////////////////////////////////////////////////////

    And this is the RC code:

    DEVICE 16F877A
    ALL_DIGITAL = TRUE
    XTAL = 20
    TRISD = $00

    DIM PWMDATA[8] AS BYTE
    DIM INDEX AS BYTE
    DIM X AS BYTE

    FOR X = 0 TO 7 'INITIATE PWMDATA
    PWMDATA[X] 0 = 255
    NEXT X
    INDEX = 0

    TXSTA = %00100110 'ASYNCHRONUS, HIGH SPEED, TRANSMISSION ENABLED.
    RCSTA = %10010000 'USART ON, 8-BIT, NO ADRESS DETECTION, CONTINOUS RECEIVE
    SPBRG = %00001010 'SET BAUDSPEED TO 113200 (HOW DO YOU CALCULATE THE ERROR?)

    MAIN:
    PORTD = $FF
    FOR X = 0 TO 255
    IF X = PWMDATA[0] THEN CLEAR PORTD.0
    IF X = PWMDATA[1] THEN CLEAR PORTD.1
    IF X = PWMDATA[2] THEN CLEAR PORTD.2
    IF X = PWMDATA[3] THEN CLEAR PORTD.3
    IF X = PWMDATA[4] THEN CLEAR PORTD.4
    IF X = PWMDATA[5] THEN CLEAR PORTD.5
    IF X = PWMDATA[6] THEN CLEAR PORTD.6
    IF X = PWMDATA[7] THEN CLEAR PORTD.7
    IF RCIF = 1 THEN GOSUB RECEIVE
    NEXT X
    GOTO MAIN

    RECEIVE:
    IF INDEX = 8 THEN INDEX = 0
    PWMDATA[INDEX] = RCREG
    INDEX = INDEX + 1
    RETURN



    Thanks for all your help!!!
    Manuel

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by manumenzella View Post

    DEVICE 16F877A
    ALL_DIGITAL = TRUE
    XTAL = 20

    DIM PWMDATA[8] AS BYTE 'VARIABLES FOR DATA TRANSMISSION

    DIM INDEX AS BYTE 'INDEX FOR DATA RECEPTION FOR PWMDATA
    DIM X AS BYTE

    DEVICE 16F877A
    ALL_DIGITAL = TRUE
    XTAL = 20

    DIM PWMDATA[8] AS BYTE
    DIM INDEX AS BYTE
    DIM X AS BYTE

    PWMDATA[X] 0 = 255

    Manuel
    That's some of the strangest PBP I've seen in awhile...must be that new version...

  5. #5
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Hi. Yes I know. I don't know why my compiles uses those commands. A relative of mine taught me basic and he tought to me like that. Is it at least readable by you guys??? I hope so!!!
    Manuel

  6. #6
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Hey by the way, in the RC code, there is an extra 0 that should be there.
    Instead of :

    FOR X = 0 TO 7 'INITIATE PWMDATA
    PWMDATA[X] 0 = 255
    NEXT X
    INDEX = 0

    It should be:

    FOR X = 0 TO 7 'INITIATE PWMDATA
    PWMDATA[X] = 255
    NEXT X
    INDEX = 0

    Thanks
    Manuel

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by manumenzella View Post
    Hi. Yes I know. I don't know why my compiles uses those commands. A relative of mine taught me basic and he tought to me like that. Is it at least readable by you guys??? I hope so!!!
    Manuel
    Maybe because it's not PBP?

  8. #8
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Ohhh Youre right! This was my uncle computer and he left the compiler installed!!! It says PBP compiler, but in About... it says proton!!!!!!!!!!!!!!!!!
    Its quite similar though. The language, i mean.
    Manuel

Similar Threads

  1. Replies: 11
    Last Post: - 12th July 2008, 02:36
  2. Pic to pic interrupt ans serial comm
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th May 2008, 22:43
  3. pc to pic serial comm and i2c eeprom
    By elektroline in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd November 2006, 05:51
  4. Replies: 5
    Last Post: - 20th March 2006, 01:34
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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