I use a ATmega16 to communicate with a TMC249.
The motor is running really smooth
I've traced the the SPI lines with a dig. scope and it seems that the TMC249 really sends this kind of invalid data.
Any ideas?
Thanx in advance
Tobias
Here's the source code
#include "TMC249.h"
cTMC249::cTMC249()
{
PhaseCount = 0;
Direction = 0;
// SPI
// Set MOSI,SS and SCK output, all others input
DDRB |= (1<<TMC249_MOSI)|(1<<TMC249_SCLK)|(1<<TMC249_SS);
DDRB &=~(1<<TMC249_MISO);
// Enable SPI, Master, set clock rate 4MHz
SPCR = (1<<SPE)|(1<<MSTR);
PORTB |= (1<<TMC249_SS);
}
volatile unsigned char B1,B2; // only for debugging
cTMC249::sDriverState cTMC249::Step(char steps, unsigned char md)
{
unsigned int io;
uState State;
PhaseCount+=steps;
if (steps != 0) Direction = steps;
if(Direction>0)
io=((TMC249_sinus_tab_r[PhaseCount & 63])<<6) | TMC249_sinus_tab_r[(PhaseCount+16) & 63];
else
io=((TMC249_sinus_tab_l[PhaseCount & 63])<<6) | TMC249_sinus_tab_l[(PhaseCount+16) & 63];
switch(md)
{
case 0:
io &= 0x7DF; // Clear mixed decay bits if mixed decay always off.
break;
case 2:
io |= 0x820; // Set mixed decay bits to 1, if desired
break;
}
PORTB &= ~(1<<TMC249_SS);
SPDR = io >> 8;
while(!(SPSR & 0x80));
B1 = SPDR;
SPDR = io;
while(!(SPSR & 0x80));
B2 = SPDR;
PORTB |= (1<<TMC249_SS);
State.Bytes.MSB = B1;
State.Bytes.LSB = B2;
return State.States;
}
