Anyway, I'm using EasyAVR and Stepper 16 click to run my stepper motor but can't get it running, I tried using SPI to alter slave registers in order to set MONTEN=1 (motor enable flag) and SLP=0 but unsuccessfully.
I read the datasheet, so basically it's 16 bit SPI communication, and to write to register first of all I need to send MSB as 1 (write) then four bit address and odd parity bit, and then data (10 bits). But nothing happens when I do that. (Obviously it's my first time using SPI so not completely sure what I'm doing).
I connected a click board to microbus 3rd port, and enabled SW5 switches (SCK, MISO, MOSI).
Here is the datasheet: https://download.mikroe.com/documents/d ... asheet.PDF
Here is my code:
Code: Select all
sbit Chip_Select at PORTB4_bit; // CS is at PB4
sbit Chip_Select_Direction at DDB4_bit;
// Clickboard is connected to microbus 3rd port
void main() {
DDRB.F3 = 1; // NXT pin
DDRA.F4 = 1; // DIR pin
// Only one slave device
Chip_Select = 1;
Chip_Select_Direction = 1;
// CSB is active low, data sampling on raising edge
SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV16, _SPI_CLK_LO_LEADING);
SPI_Set_Active(&SPI1_Read, &SPI1_Write); // Sets the SPI2 module active
// Set CSB low for between 20us and 200us to "wake ti up"
PORTB.F4 = 0;
delay_us(100);
PORTB.F4 = 1;
delay_us(350); // 250us - wake up time
// Write SLP=0
Chip_Select = 0;
SPI1_Write(0x91);
SPI1_Write(0x00);
Chip_Select = 1;
// Set MOTEN=1 (8th bit in lower byte)
Chip_Select = 0;
SPI1_Write(0x88);
SPI1_Write(0x00);
Chip_Select = 1;
delay_us(1000);
while (1) {
PORTB.F3 = 1; // Next micro-step
delay_us(1000);
PORTB.F3 = 0;
delay_us(1000);
}
}