Porting code to new PIC


Closed Thread
Results 1 to 13 of 13
  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Porting code to new PIC

    Guy's,

    Currently have a project running on an 18F4580. It uses a DS1307 RTC which uses the I2C bus, however I'm looking at adding networking to my project based on an Enc26j60 which uses the SPI interface. I've been browsing Microchips site for best part of the morning and have located what seems to be the ideal chip to port the project to. Its an 18F45K22 (http://www.microchip.com/wwwproducts...cName=en546239)

    Basically this has two MSSP however my limited knowledge of deciphering datasheets I can't work out if you can configure one MSSP as IC2 and the other as SPI and have them running at the same time ? Could someone take a look at the datasheet and advise me on my choice of chip and if I can indeed have an Ic2 and SPI bus running at the same time http://ww1.microchip.com/downloads/e...Doc/41412D.pdf

    THIA

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


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm,
    As far as I can see they are two, of each other, completely independent peripherals, see note 1 and 2 on page 208. You should have no problem setting one up for I²C and the other for SPI. Lots of registers to set up though ;-)

    Make sure to read thru the errata sheet as well, I don't see the MSSP modules being mentioned but apparently there can be some pretty serious silicon bugs. The HLVD module for example appears to be completely useless.

    /Henrik.

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for that.

    I had noted it stated independent MSSP, but I wasn't sure if it basically meant that that the chip was in SPI mode or IC2 mode. Those registers are going to be my downfall. The data sheet appears to have nearly 50 pages covering the MSSP's - any suggestions as to what PBP commands I need to achieve this mix ?

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm,
    Sorry but AFIK PBP doesn't have commands that "drives" the MSSP modules (like HSEROUT/HSERIN does with USART). I think you have to manually set up the module(s) and then, in one way or another (polling, interruptdriven etc) read and write data to them. Unfortunately I've never played with such a module - heck, I haven't even used I2CREAD/WRITE....

    /Henrik.

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


    Did you find this post helpful? Yes | No

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Dave.

    My christmas present to myself arrived today - three add-on boards for the EasyPIC5 board, one of which was the Ethernet Board - I'm going to check the data sheets for the PICs I have in my hobby box and find one with an SPI interface and have some fun !

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Thanks Dave.

    My christmas present to myself arrived today - . . .
    I was on the naughty list . . . I didn't even buy me a present!
    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.

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default dissapointed

    Uhmm. Well I finally got chance to play with some of my new add-ons last night. I had to go over to the Dark Side and downloaded the example files from Mikroelectronica's web site, but no matter what chip I used (including the recommended 18F4520) couldn't ping the "server" let alone view the basic website in the HTTP example. The 10Mb connection LED lit and there was the occasional flicker on the activity LED, and I even modified the code to flash an LED on the EasyPIC5 board prior to waiting in the packet loop so I knew the chip was running OK.

    Looking on their support forum, it seems quite a common problem, especially as the examples are for the standard (now unsupported) microbasic and not the pro version, and a lot of the threads seem to stop dead with no resolve... (unlike this lovely place where people help until the problem is fixed )

    It would be nice if PBP could support ethernet in the same way Mikrobasic does (dedicated library files and websites in strings).... maybe this could be Darrel's next gift to the PBP community

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi, Malc

    You can try to contact Bruno Gavand ( program author ) here :

    http://www.micro-examples.com/forums/

    ... hé,hé ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks,

    I've registered and awaiting confirmation so I can post the questions. I'm sure it is something simple as I'm able to compile the code, upload it and the pic runs (modified the example to flash a LED on port B a few times as it went through the code. I also get a solid LED indicating connectivity and random flashes on the activity LED. I've tried 18F4520 with 4MHz, 10Mhz, 12Mhz xtals, and various OSC settings (HS-PPL etc) in the programmer - Tried it with pull ups and pull downs on portc.0, 1 and 2. Thing is that if I re-load my thermostat code into an 18F4580 and connect the RTC on port C it runs sweet. Turn off, remove the RTC module, plug in the serial Ethernet board and then burn the demo code (modified to contain my network IP dns etc setting) I get the same issue described above.

    Tried various examples from their website and still no joy. There is only one jumper on the ethernet board which selects the voltage - in my case 5v as that's the voltage of the supply and logic lines - this (according to the basic manual and schematic) enables the 3.3 regulator and routes the logic through the level shifter



    If anyone has some PBP code to try to confirm the SPI interface works between the PIC and the ethernet board - sorta flash LED if comms established - it would help put my mind at rest that there is no fault with the board

  11. #11
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Dave, why is it that when I download the sample code for the above, I get a "symbol not previously defined SSPCON" The only difference I've made is to remove the LCD lines in the example and added the line to inc a hw file which was an edited version of the same file I used for my thermostat project

    Code:
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    
    DEFINE OSC 48 
    
    ADCON1 = $0F
    clear
    
    DEFINE LCD_DREG  PORTB           ' LCD Data port
    DEFINE LCD_DBIT  0               ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB           ' LCD Enable port
    DEFINE LCD_EBIT  5               '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB           ' LCD Register Select port
    DEFINE LCD_RSBIT 4               '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4               ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4               ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000        ' Command delay time in us 
    DEFINE LCD_DATAUS 50             ' Data delay time in us
    The example code below
    Code:
    ' Name        : SPIMAST.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6
    ' Assembler   : PM or MPASM
    ' Target PIC  : 40-pin 16F or 18F
    ' Hardware    : Lab-X1, Lab-X2 or similar
    ' Oscillator  : 4MHz internal or external
    ' Keywords    : LCDOUT, HARDWARE SPI MASTER
    ' Description : PicBasic Pro program to read and write to SPI slave
    ' using the hardware synchronous serial port. Connect SDI(master) to
    ' SDO(slave), SDO(master) to SDI(slave), AND SCK(master) to SCK(slave).
    ' Common ground is required.
    '
    ' Sends ascii "?" to request data, waits for a "!" to begin receiving data.
    ' Expects to find the ADC conversion value in the 6th position of the received
    ' string.
    '
    INCLUDE "hw.pbp"
    
    SSPEN VAR SSPCON.5   ' SSP Enable bit
    CKP   VAR SSPCON.4   ' Clock Polarity Select
    SMP   VAR SSPSTAT.7  ' Data input sample phase
    CKE   VAR SSPSTAT.6  ' Clock Edge Select bit
    SSPIF VAR PIR1.3     ' SPI interrupt flag
    
    i VAR BYTE           ' loop counter
    a VAR BYTE[6]        ' Holds 6 characters read from slave
    
       ADCON1 = 7        ' Set PORTA and PORTE to digital
       Low PORTE.2       ' LCD R/W line low (W)
       Pause 100         ' Wait for LCD to start up
    
       TRISC = 0         ' set PORTC I/O
       SSPEN = 1         ' enable SPI pins
       CKP = 0           ' clock idle low
       CKE = 0           ' transmit on idle to active transition
       SSPIF = 0         ' clear buffer full status
       SMP = 0           ' sample in middle of data
                    
    mainloop:
       GoSub getdata     ' initiate conversion and receive data
       LCDOut $fe, 1, STR a\5, DEC a[5] ' display received string
       Pause 100
       GoTo mainloop     ' do it forever
    
    getdata:                                        
       SSPBUF = "?"      ' send ? to start conversion
       GoSub letclear    ' wait for buffer to clear
       IF SSPBUF<>"!" Then getdata ' wait for reply (!)
    
       For i = 0 to 5    ' loop for 6 characters
         SSPBUF = 0      ' write to SSPBUF to start clock
         GoSub letclear  ' wait for receipt
         a[i] = SSPBUF   ' store received character in array
       Next i            ' get next character
       Return
    
    letclear:
       IF SSPIF = 0 Then letclear ' wait for SPI interupt flag
       PauseUs 25         ' 25uS fudge factor
       SSPIF = 0          ' reset flag
       Return
    
       End
    PIC is the same 18F4580 used for my Thermostat project - Help !!

  12. #12
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Check those datasheets...

    This PIC only has SSPCON1 or SSPCON2.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  13. #13
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Check those datasheets...

    This PIC only has SSPCON1 or SSPCON2.
    You beat me to it - I was wading through the datasheet and was basically going to post that question --- SSPCON1 compiles OK

Members who have read this thread : 1

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