Dspic33Fj128MC706A UART<> pic18F25K80


Today 14:34
Forum: Absolute Beginners Section
Starter: mitch
Views: 0
Replies: 4
Today 10:17
Forum: The Lounge
Starter: Tim
Views: 0
Replies: 10
Yesterday 16:25
Forum: The Lounge
Starter: See_Mos
Views: 0
Replies: 8
Yesterday 15:42
Forum: Tips 'n Tricks
Starter: canilica
Views: 0
Replies: 0
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Dspic33Fj128MC706A UART<> pic18F25K8011 days old

  1. #1
    Member basparky's Avatar
    Join Date
    Oct 2006
    Posts
    215
    Thumbs Up
    Received: 14
    Given: 15
    Total Downloaded
    741.97 MB

    0 Not allowed!

    Default Dspic33Fj128MC706A UART<> pic18F25K80

    Hi,

    I have a pic18F25K80 sending every 500ms a byte array.
    Code:
    Proc SendMessage()
    Dim ID As Byte
    Dim StrToMain[8] As Byte
    Dim wCheckSum As Word
    
    
    
    
        StrToMain[0] = 1
        StrToMain[1] = Modus
        StrToMain[2] = Command
        StrToMain[3] = HallFwd
        StrToMain[4] = HallBwd
        StrToMain[5] = HallLeft
        StrToMain[6] = HallRight
        wCheckSum = StrToMain[0] + StrToMain[1] + StrToMain[2] + StrToMain[3] + StrToMain[4] + StrToMain[5] + StrToMain[6]
        bCheckSum = wCheckSum.LowByte    
        StrToMain[7] = bCheckSum
        TMR0ON = 0
        TMR0IE = 0
        HRSOut Str StrToMain
        Interval = 0
        TMR0ON = 1
        TMR0IE = 1    
    EndProc
    
    
    GoTo Main

    I would like to catch this array in a ISR routine. In this case using the second UART RX2 from the dsPic.
    Setup:
    Code:
        Declare Hserial2_Baud = 9600
        Declare HRSOut2_Pin = PORTF.5 
        Declare HRSIn2_Pin  = PORTF.4
      
        U2MODEbits_URXINV       = 0     'Rx inverse    
        IPC7bits_U2RXIP0 = 1                          ' \
        IPC7bits_U2RXIP1 = 1                          ' | Priority interrupt level 1
        IPC7bits_U2RXIP2 = 1  
                
        U2MODEbits_UARTEN       = 1
        U2STAbits_UTXEN         = 0
        IEC1bits_U2RXIE         = 1
    ISR Routine:
    Code:
    Isr U2RXInterrupt
    
    
        Toggle LedRd
        If U2STAbits_OERR = 1 Then 
            Clear U2STAbits_OERR
            GoTo ExitInterrupt2
        EndIf
        
        InputByte[Index] = U2RXREG
        
        Inc Index
        If Index > 7 Then
            ReceivedFromJoystick = 1
        EndIf
        
        
        
        
        ExitInterrupt2:
        Clear IFS1bits_U2RXIF
    EndIsr
    In the main loop i just send out the byte array to serial terminal through U1TX.

    The problem is that the ISR is triggert (led blinks) but the U2RXREG is always empty. I have been trying all kind of scenarios but i do not get any data from this register.
    If i use something like:
    USART2BRX = HRSIn2
    HRSOut Dec USART2BRX,"\r\n"

    in the main routine i get the byte as expected...

    Does anyone know how to solve this issue?

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,279
    Thumbs Up
    Received: 380
    Given: 137
    Total Downloaded
    1.59 GB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    Comment out the error checking part of the Isr, just to make sure you are not receiving errors all the time and the array will not be filled.

    Also, if the Hrsin2 or Hrsout2 commands are not used in a program, the Baud rate and pins used in the declares will not be entered in the Asm file, so the SFRs will not be configured, so you will always receive errors. To make sure they are being used, place a simple Hrsout2 13 command in the main of the program.

    Then take a look in the Asm file (Press F2) and go to the block of asm text after "proton_main_start_:". You will see:

    bset.b TRISF,#4
    bclr.b TRISF,#5
    bset.b LATF,#5
    mov.w #0x8808,W0
    mov.w W0,U2MODE
    bset.w U2STA,#pp_utxen
    mov.w #416,W0
    mov.w W0,U2BRG


    This is the setting up of the USART2 from the declares.

    If that is the problem, and you cannot use a standard Hrsin2 or Hrsout2 in your program, you can create that code in your program by making the same Asm code in BASIC form:

    Input __hrsin2_port.__hrsin2_pin
    High __hrsout2_port.__hrsout2_pin
    U2MODE = $8808
    Set U2STAbits_UTXEN
    U2BRG = 416


    Place this in your setup procedure so it is run before USART2 is accessed.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member basparky's Avatar
    Join Date
    Oct 2006
    Posts
    215
    Thumbs Up
    Received: 14
    Given: 15
    Total Downloaded
    741.97 MB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    Thanks top204, after following your instructions by checking the generated ASM file i noticed your remarks and got to a workable solution. I have an issue with the data received. I hope you have time for another look at my code please.



    Init receiver UART code: (dspic)
    Code:
        Input __hrsin2_port.__hrsin2_pin
        High __hrsout2_port.__hrsout2_pin
        U2MODE = $8808
        Set U2STAbits_UTXEN       
        Set IEC1bits_U2RXIE
    
    
        
        Declare Hserial2_Baud = 9600
        Declare HRSOut2_Pin = PortF.5 
        Declare HRSIn2_Pin  = PortF.4    
        
        IPC7bits_U2RXIP0 = 1                          ' \
        IPC7bits_U2RXIP1 = 1                          ' | Priority interrupt level 7 highest priority interrupt
        IPC7bits_U2RXIP2 = 1
    I'm currently receiving a string with data every 500ms. The ISR routine looks like this:
    Code:
    Isr U2RXInterrupt    
        ID = 121 'Id from joystick
        Toggle LedRd    
        If U2STAbits_OERR = 1 Then
            Clear U2STAbits_OERR
            GoTo ExitInterrupt2
        EndIf
            
        USART2bRx = U2RXREG    
        
        'catch start off message
        If USART2bRx = ID Then
            SOM = 1
            Index2 = 0
        EndIf
        'load 8 bytes into array
        
        If SOM = 1 Then
            StrJoyStick[Index2] = USART2bRx
            Inc Index2
            If Index2 > 7 Then
                Index2 = 0
                ReceivedFromJoystick = 1
                SOM = 0
            EndIf
        EndIf
        
        ExitInterrupt2:
        Clear IFS1bits_U2RXIF
    EndIsr
    The sender (18F pic) code is:
    Code:
    Proc SendMessage()
    Dim ID As Byte
    Dim StrToMain[10] As Byte
    Dim wCheckSum As Word
    
    
    '0'1        ID = 1
    '1'0-3      Modus
    '2'         Command
    '3'         HallFwd 
    '4'         HallRev
    '5'         HallLeft
    '6'         HallRight
    '7'         ChecckSum
        StrToMain[0] = 121
        StrToMain[1] = Modus
        StrToMain[2] = Command
        StrToMain[3] = HallFwd
        StrToMain[4] = HallBwd
        StrToMain[5] = HallLeft
        StrToMain[6] = HallRight
        wCheckSum = StrToMain[0] + StrToMain[1] + StrToMain[2] + StrToMain[3] + StrToMain[4] + StrToMain[5] + StrToMain[6]
        bCheckSum = wCheckSum.LowByte    
        StrToMain[7] = bCheckSum
        TMR0ON = 0
        TMR0IE = 0
        HRSOut Str StrToMain
        Interval = 0
        TMR0ON = 1
        TMR0IE = 1    
    EndProc
    If StrToMain[0 to 7] is the number 0 the receiver ISR doesnt work anymore? anything else than 0 is fine...
    I will try to find why this is myself but it doesn't make sense to me

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Member basparky's Avatar
    Join Date
    Oct 2006
    Posts
    215
    Thumbs Up
    Received: 14
    Given: 15
    Total Downloaded
    741.97 MB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    Aha, I think the number 0 in the string is recognized as end of string / null terminator. Mmmm does this mean i cannot send 0? The number in StrToMain[3-6] are between 50 and 230 so adding 48 as ascii doesnt work without splitting the bytes i guess...

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,079
    Thumbs Up
    Received: 190
    Given: 169
    Total Downloaded
    4.66 GB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    FWIW the number 0 has a value of $30 or 48 decimal, the string terminator is usually $00, as in win32 ASCIIZ
    George.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    454
    Thumbs Up
    Received: 84
    Given: 0
    Total Downloaded
    243.13 MB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    I think the number 0 in the string is recognized as end of string / null terminator. Mmmm does this mean i cannot send 0?
    I don't know if it's always been this way, but you're right... the 'STR' modifier is causing it to treat the array as a null-terminated string, and not just an array of bytes. If you want to send binary data you'll have to do it another way.

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,079
    Thumbs Up
    Received: 190
    Given: 169
    Total Downloaded
    4.66 GB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    Sorry basparky, I misunderstood what you meant by "the number 0".
    George.

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,279
    Thumbs Up
    Received: 380
    Given: 137
    Total Downloaded
    1.59 GB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    Sorry for the delay in replying, I'm currently working on 2 projects so my mind is constantly at work. :-)

    I see no reason why a 0 would not be accessed, the Str modifier on PIC24 devices does not use them as a null or a terminator. To make sure it is not that, and that you are actually receiving the data, transmit each element of the array seperately, then you will have a definate answer to where the problem lies. For example:

    Hrsout Dec StrToMain[0], ",", Dec StrToMain[1], ",", Dec StrToMain[2], ",", Dec StrToMain[3] etc...

    With any coding problem, it is always better to simplify the code to try and identify the bottleneck, then when it is working, use different techniques to improve the code and test as changes are made. In the thousands of programs I've created over the, far too many years :-) , this is the way I have always implemented changes, or the beginnings of a code project. i.e. Make sure the principle works, then make changes to improve it.
    Last edited by top204; 13th August 2019 at 11:55.

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    454
    Thumbs Up
    Received: 84
    Given: 0
    Total Downloaded
    243.13 MB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    The library routine SB@STROUT terminates when it sees a 0 byte in the array.

    SB@STROUT is called when using
    Code:
    Dim StrToMain[10] As Byte
    
    HRSOut Str StrToMain
    
    ; generated asm
    SB@STROUTLP
        ....
        movff PP2,FSR0L
        movff PP2H,FSR0H
        movf INDF0,W,0     <<<<<<<<
        btfsc STATUS,2       <<<<<<<<
        return
        rcall _BYTE__SEND_

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,279
    Thumbs Up
    Received: 380
    Given: 137
    Total Downloaded
    1.59 GB

    0 Not allowed!

    Default Re: Dspic33Fj128MC706A UART<> pic18F25K80

    That code is for an 18F device only. The PIC24 and dsPIC devices have an entirely different mnemonic set. :-) The code for the 14-bit core devices is also different to the 18F, and so is the enhanced 14-bit core code different to 18F and standard 14-bit.

    The question is concerning a dsPIC device.

    The Str modifier was first implemented before I added true strings to the Proton compiler, so I had to leave it as it was, but Proton24 had Strings from the start, so the Str code for them is:

    mov.w #4,W0
    mov.w W0,__OSM
    mov.w #MyArray,W1
    mov.w #0,W3
    1:
    push W3
    push W1
    mov.b [W1 + W3],W0
    call __hrsout1
    pop W1
    pop W3
    inc.w W3,W3
    mov.w #20,W0
    sub.w W3,W0,[W15]
    bra leu,1b


    And there is no null termination. It cycles the length of the array.

    I've never been a one to use the built in modifiers when scanning arrays and strings etc. I always like it better doin git in a loop:

    For Index = 0 To Bound(MyArray)
    Hrsout MyArray[Index]
    Next


    The above loop can also be elaborated to exit when a particular byte is found or stop certain values being outputted etc...
    Last edited by top204; 13th August 2019 at 18:17.

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. UART Terminal
    By AlbertoFS in forum Amicus 18
    Replies: 1
    Last Post: 21st April 2016, 11:09
  2. PIC18F25K80 ADC goes backward when over 50%
    By Tim in forum Proton Plus Compiler v3
    Replies: 23
    Last Post: 8th April 2016, 14:01
  3. UMC Bootloader for Pic18F25K80
    By Tim in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 23rd January 2016, 10:43
  4. PWM on dsPic33FJ128MC706A
    By basparky in forum Proton 24
    Replies: 2
    Last Post: 8th January 2016, 09:45
  5. 1 UART 2 devices
    By all77 in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 12th February 2008, 10:09

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts