TMC249 response invalid

TMC249 response invalid

Postby TW » 30 Aug 2008, 18:56

Hello,

I use a ATmega16 to communicate with a TMC249.
The motor is running really smooth :D but the response of the TMC249 (status bits) is invalid and toggle by pure chance :?
I've traced the the SPI lines with a dig. scope and it seems that the TMC249 really sends this kind of invalid data. :cry:

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;
}
TW
Newbie
Newbie
 
Posts: 1
Joined: 30 Aug 2008, 18:22

Postby TRINAMIC_BD » 01 Sep 2008, 09:32

When shifting 16 Bits, please be aware, that the status bits shift left by 4 bits for your read out register. We have not seen a scrambled output from a SPI chip before.
User avatar
TRINAMIC_BD
Site Admin
 
Posts: 2436
Joined: 25 Jul 2006, 12:21
Location: Hamburg (Germany)


Return to TMC236 / TMC239 / TMC246 / TMC249

Who is online

Users browsing this forum: No registered users and 1 guest