Connect with us

SPI & ADIS16251

Discussion in 'Microcontrollers, Programming and IoT' started by laleh22, Apr 12, 2012.

Scroll to continue with content
  1. laleh22

    laleh22

    1
    0
    Apr 12, 2012
    Hi :)
    I want to analyze ADIS16251ACCZ output in PC.
    I have used micro (atmega16) and connect ADIS16251ACCZ to micro and then connect micro to PC. how can I drive ADIS16251ACCZ?
    micro can send and receive only 8 bit but sensor have 16 bit data frame!!

    This is my code in code vision program.
    please check it. I can't have correct output in PC.
    please help me.

    thanks



    Chip type : ATmega16

    Program type : Application

    Clock frequency : 1.000000 MHz

    Memory model : Small

    External SRAM size : 0

    Data Stack size : 256

    *****************************************************/



    #include <mega16.h>



    // Standard Input/Output functions

    #include <stdio.h>

    #include <delay.h>

    // SPI functions

    #include <spi.h>



    // Declare your global variables here



    void main(void)

    {

    // Declare your local variables here

    int d1;

    int d2;

    // Input/Output Ports initialization

    // Port A initialization

    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

    PORTA=0x00;

    DDRA=0x00;



    // Port B initialization

    // Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In

    // State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T

    PORTB=0x00;

    DDRB=0xB0;



    // Port C initialization

    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

    PORTC=0x00;

    DDRC=0x00;



    // Port D initialization

    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

    PORTD=0x00;

    DDRD=0x00;


    // USART initialization

    // Communication Parameters: 8 Data, 1 Stop, No Parity

    // USART Receiver: Off

    // USART Transmitter: On

    // USART Mode: Asynchronous

    // USART Baud Rate: 1200

    UCSRA=0x00;

    UCSRB=0x08;

    UCSRC=0x86;

    UBRRH=0x00;

    UBRRL=0x33;


    // SPI initialization

    // SPI Type: Master

    // SPI Clock Rate: 250.000 kHz

    // SPI Clock Phase: Cycle Start

    // SPI Clock Polarity: High

    // SPI Data Order: MSB First

    SPCR=0x5C;

    SPSR=0x00;



    //Factory Calibration Restore ########################################

    PORTB.4=0;

    spi(0b10111110);

    spi(0b00000010);

    PORTB.4=1;



    delay_us(50);



    PORTB.4=0;

    spi(0b10111111);

    spi(0b00000000);

    PORTB.4=1;



    delay_us(50);



    while (1)

    {

    //Reading GYRO_OUT#########################################

    PORTB.4=0;

    spi(0b00000101);

    spi(0b00000000);

    PORTB.4=1;



    delay_us(50);



    PORTB.4=0;

    d1=spi(0);

    d2=spi(0);

    PORTB.4=1;



    delay_us(50);



    printf("d1=%d",d1);//sending to PC

    printf("d2=%d",d2);//);//sending to PC

    delay_ms(400);

    };

    }
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    9,902
    2,097
    Nov 17, 2011
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-