Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2014
    Location
    Aarhus, Denmark
    Posts
    13

    Default Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why?

    Both running 5V
    9600 Baud
    Uses HSERIN PORTC.7

    Is there something with logic voltage levels I should be aware of?

    Have tried with pull up 4K7 and 10K ...

    Receives only 3 nonsense letters

    - Jacob

  2. #2
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    Just a stab in the dark.... HSERIN will only work directly using TRUE state. Have you tried using an inverter or, alternatively, can you do a quick test using SERIN with N9600?

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


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    Hi Jacob,
    At this point it is a little like winking at a girl in the dark, you know what you did but almost nobody else does. Some code samples would help a bunch.
    Arduino libraries are pretty much turn key code in a box wrapped in birthday paper. PBP is a bit more hands on. A good example of hserin can be found here:http://www.picbasic.co.uk/forum/show...light=backpack
    There was an article posted from this thread, I cannot find it right now, or any articles for that matter, may be a script blocker on my end . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    Is this the one you are looking for?
    http://www.picbasic.co.uk/forum/cont...rial-backpacks
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    Are you able to communicate with your PC?

    The problem can be at either ends. It would help to know if the data is sent properly so you can concentrate on the culprit.

    Check your PBP manual on how to set up the link, or search here.

    Do you have a logic probe?

    Robert

  6. #6
    Join Date
    Feb 2014
    Location
    Aarhus, Denmark
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    Hi All

    All right. Thanks for the response.

    It's a bit embarrassing and I'm pretty confused for a sudden does it all as it should without I know what caused it. It's very simple setup but for several days it has teased me.

    Test set-up:

    Name:  PIC to Arduino.jpg
Views: 1421
Size:  135.0 KBName:  Arduino to PIC.jpg
Views: 1242
Size:  145.0 KB

    Here's the test code I'm using:

    18F45K22:
    Code:
    #CONFIG
        CONFIG  FOSC = INTIO67        ; Internal oscillator block
        CONFIG  PLLCFG = ON           ; 
        CONFIG  PRICLKEN = OFF        ; Primary clock can be disabled by software
        CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor disabled
        CONFIG  IESO = OFF            ; Oscillator Switchover mode disabled
        CONFIG  PWRTEN = OFF          ; Power up timer disabled
        CONFIG  BOREN = SBORDIS       ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        CONFIG  BORV = 190            ; VBOR set to 1.90 V nominal
        CONFIG  WDTEN = ON            ; WDT is always enabled. SWDTEN bit has no effect
        CONFIG  WDTPS = 32768         ; 1:32768
        CONFIG  CCP2MX = PORTC1       ; CCP2 input/output is multiplexed with RC1
        CONFIG  PBADEN = OFF          ; PORTB<5:0> pins are configured as digital I/O on Reset
        CONFIG  CCP3MX = PORTB5       ; P3A/CCP3 input/output is multiplexed with RB5
        CONFIG  HFOFST = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  T3CMX = PORTC0        ; T3CKI is on RC0
        CONFIG  P2BMX = PORTD2        ; P2B is on RD2
        CONFIG  MCLRE = EXTMCLR       ; MCLR pin enabled, RE3 input pin disabled
        CONFIG  STVREN = ON           ; Stack full/underflow will cause Reset
        CONFIG  LVP = OFF             ; Single-Supply ICSP disabled
        CONFIG  XINST = OFF           ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG = OFF           ; Disabled
        CONFIG  CP0 = OFF             ; Block 0 (000800-001FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (002000-003FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (004000-005FFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (006000-007FFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-001FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (002000-003FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (004000-005FFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (006000-007FFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    #ENDCONFIG
    
    
    DEFINE OSC 64
                             
    ' Setup PLL for 64 MHZ
    OSCCON = 110100 ; 16 mhz (NOTE: SCS=0 so PLL works)
    OSCTUNE.6 = 1 ;  PLL enable Mhz * 4 
    
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    ANSELD = 0
    ANSELE = 0
    
    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA    90h
    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA    20h
    ' Set baud rate
    DEFINE HSER_BAUD    9600
    DEFINE HSER_CLROERR 1  ' Auto clear over-run errors
    
    char Var byte  ' Storage for serial character
    
        Pause 2000
    
        Hserout ["PIC - UP RUNNING :-)", 13, 10] ' Send text followed by carriage return and linefeed
    
    start:
           pause 10
           toggle PORTC.0  ' Alive LED 
    
    mainloop:
           Hserin 10000, start, [char]    ' Get a char from serial port
           pause 10
           Hserout [char]        ' Send char out serial port
           Goto mainloop        ' Do it all over again
       
    End
    Arduino Uno (only the chip - ATmega328p):
    Code:
    int led = 13;
    
    int incomingByte = 0;   // for incoming serial data
    
    void setup() {
      Serial.begin(9600);               
      // initialize the digital pin as an output.
      pinMode(led, OUTPUT);
      Serial.println("Arduino UNO - UP RUNNING...");  
    }
    
    // the loop routine runs over and over again forever:
    void loop() {
      digitalWrite(led, HIGH);   
      delay(100);               
      digitalWrite(led, LOW);    
      delay(900);               
    
      if (Serial.available() > 0) {
        while (Serial.available()) {
          Serial.print((char)Serial.read());
        }
        Serial.println();
      }
    }

  7. #7
    Join Date
    Feb 2014
    Location
    Aarhus, Denmark
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    However,

    why does this code not. It receives nothing

    Hserin 10000, start, [WAITSTR buffer\3]

    I need to wait for the three characters from an Arduino



    Code:
    ' Hserin test
    ' For PIC 18F45K22 with PLL
    ' Compiler used: PBP3
    ' Assembler used: MPASMX
    
    
    #CONFIG
        CONFIG  FOSC = INTIO67        ; Internal oscillator block
        CONFIG  PLLCFG = ON           ; 
        CONFIG  PRICLKEN = OFF        ; Primary clock can be disabled by software
        CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor disabled
        CONFIG  IESO = OFF            ; Oscillator Switchover mode disabled
        CONFIG  PWRTEN = OFF          ; Power up timer disabled
        CONFIG  BOREN = SBORDIS       ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        CONFIG  BORV = 190            ; VBOR set to 1.90 V nominal
        CONFIG  WDTEN = ON            ; WDT is always enabled. SWDTEN bit has no effect
        CONFIG  WDTPS = 32768         ; 1:32768
        CONFIG  CCP2MX = PORTC1       ; CCP2 input/output is multiplexed with RC1
        CONFIG  PBADEN = OFF          ; PORTB<5:0> pins are configured as digital I/O on Reset
        CONFIG  CCP3MX = PORTB5       ; P3A/CCP3 input/output is multiplexed with RB5
        CONFIG  HFOFST = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  T3CMX = PORTC0        ; T3CKI is on RC0
        CONFIG  P2BMX = PORTD2        ; P2B is on RD2
        CONFIG  MCLRE = EXTMCLR       ; MCLR pin enabled, RE3 input pin disabled
        CONFIG  STVREN = ON           ; Stack full/underflow will cause Reset
        CONFIG  LVP = OFF             ; Single-Supply ICSP disabled
        CONFIG  XINST = OFF           ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG = OFF           ; Disabled
        CONFIG  CP0 = OFF             ; Block 0 (000800-001FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (002000-003FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (004000-005FFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (006000-007FFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-001FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (002000-003FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (004000-005FFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (006000-007FFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    #ENDCONFIG
    
    
    DEFINE OSC 64
                             
    ' Setup PLL for 64 MHZ
    OSCCON = %01110100 ; 16 mhz (NOTE: SCS=0 so PLL works)
    OSCTUNE.6 = 1 ;  PLL enable Mhz * 4 
    
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    ANSELD = 0
    ANSELE = 0
    
    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA	90h
    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA	20h
    ' Set baud rate
    DEFINE HSER_BAUD	9600
    DEFINE HSER_CLROERR 1  ' Auto clear over-run errors
    
    buffer Var byte[3]  ' Storage for serial character
    
    	Pause 2000
    
    	Hserout ["PIC - UP RUNNING :-)", 13, 10] ' Send text followed by carriage return and linefeed
    
    start:
       	pause 10
    
    mainloop:
       	toggle PORTC.0  ' Alive LED 
       	Hserin 10000, start, [WAITSTR buffer\3]	
       	pause 10
    	Hserout [str buffer\3]		
       	Goto mainloop		' Do it all over again
       
    End

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    Hi,
    WAITSTR is used to wait for a specific string of characters and THEN continue.
    In this case it'll sit there and receive charcters until three bytes in a row matches what you've stored in buffer and THEN continue with the program. Since you don't have anything in stored in buffer (all zero) you'd need to send three null bytes in order for the program continue.

    If you want to receive three bytes, any three bytes, and store them in buffer then use STR Buffer \3 instead of WAITSTR Buffer \3. See section 2.10 in the PBP3 manual for more details.

    /Henrik.

  9. #9
    Join Date
    Feb 2014
    Location
    Aarhus, Denmark
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: Serial: PIC18F45K22 -> (Arduino) Uno = works | Uno -> PIC18F45K22 = fails Why

    Hi Henrik

    Yes you are right

    I found this:

    http://www.picbasic.co.uk/forum/show...hlight=waitstr

    It clarified some things for me

    I will use this format for receiving: #xxx

    Hserin 10000, start, [WAIT("#"), STR buffer\3]

    - Jacob

Similar Threads

  1. PIC18F45K22, Pbp and 16*16 rgb led matrix, will speed be enough?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th May 2013, 04:45
  2. "Simon Says" the game code for PIC18F45K22
    By Tamirbm in forum General
    Replies: 1
    Last Post: - 12th May 2013, 02:29
  3. How to Interface PIC24FJ256GA110 with an Arduino UNO?
    By sharath12 in forum Code Examples
    Replies: 2
    Last Post: - 8th April 2012, 19:06
  4. Replies: 6
    Last Post: - 22nd March 2012, 12:13
  5. Serial communication fails after long pause
    By brid0030 in forum General
    Replies: 4
    Last Post: - 13th February 2008, 19:56

Members who have read this thread : 2

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

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