two serial ports


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: two serial ports

    Scampy,

    I'm pretty sure the issue you are having with I2CWRITE vs LCDOUT is two-fold.
    1. Using Output String Modifiers
    2. The use of Brackets "[ ]" with I2CWRITE

    First and foremost, PBP does not support "ALL TYPES" of Output String Modifiers for use with the I2CWRITE command.
    It only supports one type of modifier with this command, the "STR" modifier.

    From the PBP Manual for Output Modifiers:

    2.11 Output Modifiers for Formatting Strings

    The following information applies to output commands ARRAYWRITE, DEBUG, SEROUT2, HSEROUT, HSEROUT2, and LCDOUT.
    I2CWRITE is not listed above.

    Continuing from the PBP Manual for Output Modifiers for Formatting Strings:
    All of these commands accept an item list to determine output.
    Numeric data included in this item list can be converted to ASCII strings using the following modifiers.

    Output Modifiers for Formatting Strings
    Modifier Operation
    {I}{S}DEC{1..10} Send decimal digits
    {I}{S}BIN{1..32} Send binary digits
    {I}{S}HEX{1..8} Send hexadecimal digits
    REP char\count Send character c repeated n times
    STR ArrayVar{\count} Send string of n characters
    So trying to use DEC, BIN, HEX or REP with I2CWRITE will fail to compile.
    The "Bad expression" compile error you get is due to the fact you are trying to use the "dec1" Output String Modifier with I2CWRITE, which is not supported.

    However I2CWRITE does support the "STR" modifier.

    From the PBP Manual for I2CWRITE:
    I2CWRITE
    "A modifier, STR, may be included before the variable name. This can be used to write an entire array (string) at once..."
    "... If STR is specified, the following variable must be the name of a word or byte array, followed by a backslash (\) and a count:"

    What you can possibly do is use ARRAYWRITE to store all of your "String" data into an array (with modifiers) and then
    use I2CWRITE with the "STR x\n" modifier to output your formatted string, which is supported.

    e.g.
    Code:
    myOutArray var byte[8]
    
    ARRAYWRITE myOutArray, ["TT", dec1 (Pid_channel + 1), 0]
    
    I2CWRITE SDA, SCL, I2CSlaveAddress, [STR myOutArray\4]	' \4 for "TT10" 4 bytes, which is what ["TT", dec1 Pid_channel+1, 0] would be assuming Pid_channel = 0.
    Lastly, the issue of when to use brackets "[ ]" with I2CWRITE.
    Although sometimes you can compile without errors when not using brackets.
    I have found this seems to be for simple cases.
    If you have complex statements in you variable list, then you need to use brackets.
    Which is what you are seeing the "Expected '['" and "Expected ']'" compile errors from.
    It think it is trying to parse the complexity of the input to the I2CWRITE command and gets lost, so errors out.
    Then once you put the brackets around your list of data variables it errors out due to the unsupported "dec1" modifier.

    I always surround my data variable list in this and other commands with brackets and do not have problems.

    Hope this helps.
    Regards,
    TABSoft

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: two serial ports

    Tabsoft, thanks for the reply.

    Would that explain the following:

    When using HSEROUT the line
    Code:
    Hserout ["TT",#CounterA Dig 1,#CounterA Dig 0,0]
    Compiles without errors... but
    Code:
    serout portb.0,T9600,[DEC1 Pid_channel+1,0] 'or the following
    serout2 portb.0,T9600,["TT",DEC1 Pid_channel+1,0]
    Fails......

    If what you are saying about the modifiers, why will they work with the hardware command, but not with the serial command ??

  3. #3
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: two serial ports

    No the modifiers will not work with SERIN or SEROUT.
    But, they will work with SERIN2 and SEROUT2.
    SERIN2/SEROUT2 replaced the old SERIN/SEROUT commands and added new functionality including the support of Input/Output string modifiers.
    Regards,
    TABSoft

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: two serial ports

    OK I have an option (possibly ?)

    As the GLCD driver and the simple code likes the HSEROUT command lets look at using SEROUT for the communications with the PC application...Before I try this can anyone confirm if this will work with the serial option

    Code:
        IF RCIF=1 THEN GOSUB coms                   ; Check to see if PC application connected
    I'm assuming that it's looking at the hardware port on the PIC ??

  5. #5
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: two serial ports

    Unfortunately No.

    "IF RCIF = 1 THEN GOSUB coms" will not work with the Software-based SERIN/SERIN2 commands.
    The RCIF EUSART Receive Interrupt Flag bit in the PIR1 PERIPHERAL INTERRUPT REQUEST (FLAG) REGISTER 1, is tied directly to the HW EUSART RX pin (PORTC.7). It is part of the PIC functionality of the EUSART hardware module.
    Regards,
    TABSoft

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: two serial ports

    Thanks again,

    I'll see if the PC application needs that action, and if not I'll try re-write the section that deals with sending and receiving data from the PC to use serial coms, thus leaving the hardware port on the PIC to deal with cons to the GLCD driver board, which for some reason or another accepts the modifiers DEC 1 etc

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: two serial ports

    Well after a lot of head scratching I have it working. No matter what I tried it still work and kept halting - Off board Tabsoft stated it worked fine for him using PBP3 so I downloaded the 15 day trial, confirmed it worked, but then as it screwed up my pbp2.60 setting, un-installed it and pointed MSC back at the PBP2.6 folder... tried again and it worked (WT* and other expletives filled the air at this point)

    Anyway, just to clear things up, I now have the GLCD running via a driver board using PORTB.0 and software serial commands (SEROUT2) and the PC application communicates with the PIC via an FTDI chip on the PICs hardware UART - and it updates juts fine

    Rightt onto the next part of tidying up the menus before replacing the FTDI chip with an ES8622 Wi-Fi module - stand by guys, no doubt I'll have a few more questions for you.

    On a serious note, I want to publically shout out a big THANK YOU to Tabsoft for all his help and contributions, both on and off the board - I'm also slowly understanding more of what I'm doing, and how PBP and it's commands work

Similar Threads

  1. defines values for 2nd / 3rd serial ports
    By longpole001 in forum General
    Replies: 3
    Last Post: - 29th January 2015, 01:45
  2. serial ports, the servo control.
    By m.nobre in forum Serial
    Replies: 0
    Last Post: - 7th December 2009, 16:16
  3. multipal serial ports
    By Andre_Pretorius in forum Serial
    Replies: 2
    Last Post: - 11th September 2007, 14:53
  4. How many serial ports can 1 PIC handle?
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd March 2005, 04:34
  5. Which PIC supports 2 HW serial ports?
    By charliez in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th July 2004, 08:01

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