Help with MicroMag3 SPI interface to PIC


Closed Thread
Results 1 to 4 of 4
  1. #1
    kaan's Avatar
    kaan Guest

    Post Help with MicroMag3 SPI interface to PIC

    Hello,
    I am trying to interface PNI MicroMag3 Magnetometer sensor board to PIC16F877 @4Mhz. I am using SPI with SHIFTIN/SHIFTOUT commands. But I get garbage from input.
    I ve tried to slow down communication with DEFINE SHIFT_PAUSEUS, but it did not fix.

    Is there anyone, have used MicroMag3 with a PIC.

    Please help
    Kaan

  2. #2
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    One thing I've been hit with, is not setting the mode numbers correctly. It's easier on shiftout with fewer choices. What is the SPI mode, and polarity? Many SPI devices shift their data out while info is being shifted in. With the PicBasic routine, you will lose this data. Hardware SPI is more difficult to set up initially, but is bi-directional, and easy to work with once set up. Any data sheets for the device?

    Ron

  3. #3
    Join Date
    Jan 2006
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    There is a sample code file for the BS2 on PNI website

    http://www.pnicorp.com/resources?nodeId=c40c

    You can use the software shiftin/out provided by PBP, no need for hardware SPI.

    Zenon

  4. #4
    kaan's Avatar
    kaan Guest


    Did you find this post helpful? Yes | No

    Default My code

    Thank you zenon, I have already used PNI code for BS2, but slighty modifed for PBP. Here is my code


    INCLUDE "modedefs.bas" ' Include serial modes

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 9600
    DEFINE SHIFT_PAUSEUS 100


    datain VAR PORTB.0 'SPI Data in
    dataout VAR PORTB.1 'SPI Data out
    clock VAR PORTB.2 'SPI Clock
    devsel VAR PORTB.3 'Device Select
    ready VAR PORTB.4 'Data Ready
    reset VAR PORTB.5 'Reset

    cmd VAR BYTE
    result VAR WORD

    TRISB.0 = 1
    TRISB.1 = 0
    TRISB.2 = 0
    TRISB.3 = 0
    TRISB.4 = 1
    TRISB.5 = 0
    reset = 0

    HSerout ["Magnetometer Test",10,13]
    TRISB.7 = 0
    PORTB.7 = 1
    Pause 200
    PORTB.7 = 0
    Pause 200
    PORTB.7 = 1
    devsel = 1
    devsel = 0 ' select device
    basla:
    Low reset
    PulsOut reset,5 ' device reset
    ShiftOut dataout,clock,MSBFIRST,[%01000001] ' command for X axsis
    beklex: IF ready = 0 Then beklex
    ShiftIn datain,clock,MSBPRE,[result\16]
    Pause 1
    HSerout ["x= ",SDEC result," "] '

    Low reset
    PulsOut reset,5 ' device reset
    ShiftOut dataout,clock,MSBFIRST,[%01000010] ' command for Y axsis
    bekley: IF ready = 0 Then bekley
    ShiftIn datain,clock,MSBPRE,[result\16]
    Pause 1
    HSerout ["y= ",SDEC result," "]

    Low reset
    PulsOut reset,5 ' device reset
    ShiftOut dataout,clock,MSBFIRST,[%01000011] ' command for Z axsis
    beklez: IF ready = 0 Then beklez
    ShiftIn datain,clock,MSBPRE,[result\16]
    Pause 1
    HSerout ["z= ",SDEC result,10,13]


    GoTo basla


    Here is the data sheet for device
    https://www.pnicorp.com/downloadReso...Data+Sheet.PDF
    Last edited by kaan; - 31st May 2006 at 23:26.

Similar Threads

  1. Master SPI interface to LCD/OLED??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2009, 23:44
  2. SPI Communication between two pic 16f877
    By anti83 in forum Serial
    Replies: 1
    Last Post: - 5th July 2008, 21:06
  3. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42
  4. SPI configuration PIC versus Atmel
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th July 2007, 19:17
  5. SPI on a pic without hardware SPI?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th April 2006, 13:29

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