Help with MicroMag3 SPI interface to PIC


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    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