Quantcast
Channel: Motor drivers forum - Recent Threads
Viewing all articles
Browse latest Browse all 13252

DRV8301

$
0
0

I wanted to communicate with DRV8301 by using ATMEGA 16 microcontroller. when i send the read command 0x9000 (to read control register 1) the ouput data that i got from SDO pin is 0x0600 but i expected to got 0001000000000000 or 0x1000.

here is my code-->

/*
 * SPI.c
 *
 * Created: 07-Aug-16 15:37:48
 *  Author: Shashank more
 */

#ifndef F_CPU
#define F_CPU 16000000UL
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    DDRB=(1<<4)|(1<<5)|(1<<7);    // SCS, MISO and MOSI pins
    PORTB|=(1<<0)|(1<<1)|(1<<4);  // toggle SCS high
    SPCR=(1<<SPE)|(1<<MSTR)|(1<<CPHA);
    char i,j=0,k;
    while(1)
    {
                PORTB&= ~(1<<4);    // assert chip select
                _delay_us(50);
                SPDR=0x98;      // MSB nibble sending to DRV8301
                while (!(SPSR & (1<<SPIF)));
                SPSR|=(1<<SPIF);
                i=SPDR;      // store half nibble of SDO pin
                _delay_us(200);
                SPDR=0x00;     // LSB nibble  sending to DRV8301
                while (!(SPSR & (1<<SPIF)));
                SPSR|=(1<<SPIF);
                _delay_us(50);
                PORTB|=(1<<4);    // de-assert  chip select
                k=SPDR;    // store another half nibble of SDO pin
    }
}


Viewing all articles
Browse latest Browse all 13252

Trending Articles