Hi to all forum users,
i'm academic student (and newbie) and i'm working, together with another student, at port Adafruit motorshield library to stm32f303 with chibios enviroment.
This motorshield uses a 74HC595 shift register e two L293D to drive four dc motor and two stepper motor.
After a series of experiments we realized we had problems with the shifit register, Asthe if we try to drive the motors directly with L293D these work.
Is there anyone who has had experience with 74HC595 shift register and stm32f303 and can help us?
PS
excuse me for my bad english and i hope not to have posted the wrong section!
Adafruit motorshield port
Re: Adafruit motorshield port
Please tell us exactly what problem you are facing and attach the corresponding code. Otherwise we cannot help you.
~ Tectu
~ Tectu
-
renegade82
- Posts: 13
- Joined: Thu Jul 03, 2014 12:21 pm
Re: Adafruit motorshield port
This is a code :
Code: Select all
#include "ch.h"
#include "hal.h"
static PWMConfig pwmcfg = {
1000000, // 1MHz PWM clock frequency
10000, // PWM period 10 milliseconds
NULL,
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
},
0,
0
};
int main(void) {
halInit();
chSysInit();
/****************************************************************************
* ADAFRUIT MOTOR SHIELD
****************************************************************************/
int i;
// MC.ENABLE
pwmStart(&PWMD3, &pwmcfg);
palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2)); // PWM
palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 4, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 7, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 8, PAL_MODE_OUTPUT_PUSHPULL);
palClearPad(GPIOB,7); // motorenable
// RESET
palClearPad(GPIOB,12); //motorlatch
palClearPad(GPIOB,8); //motordata
for (i = 0; i < 8; ++i) {
palClearPad(GPIOB,4); //motorclock
palClearPad(GPIOB,8);//motordata 0
palSetPad(GPIOB,4); //motorclock
}
palSetPad(GPIOB,12); //motorlatch
while (1) {
// RUN FORWARD (OUTPUT SHIFT REGISTER => Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 = 0 0 0 0 0 1 0 0)
pwmEnableChannel(&PWMD3, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 6000));
palClearPad(GPIOB,12); //motorlatch
palClearPad(GPIOB,8); //motordata 0
for (i = 0; i < 8; ++i) {
palClearPad(GPIOB,4); //motorclock
if(i==5) // run to foward test
palSetPad(GPIOB,8);//motordata 1
else
palClearPad(GPIOB,8);//motordata 0
palSetPad(GPIOB,4); //motorclock
}
palSetPad(GPIOB,12); //motorlatch
}
return 0;
}- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Adafruit motorshield port
Hi,
You can clock the shift register using a SPI port (sending one byte), if you have N cascaded shift registers then send N bytes.
BTW the cube project does exactly this.
Giovanni
You can clock the shift register using a SPI port (sending one byte), if you have N cascaded shift registers then send N bytes.
BTW the cube project does exactly this.
Giovanni
-
renegade82
- Posts: 13
- Joined: Thu Jul 03, 2014 12:21 pm
Re: Adafruit motorshield port
Thanks for the reply Giovanni,
how can I access the source code of chibi cube, the links on this forum don't works anymore!
how can I access the source code of chibi cube, the links on this forum don't works anymore!
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
-
renegade82
- Posts: 13
- Joined: Thu Jul 03, 2014 12:21 pm
Re: Adafruit motorshield port
i'm tried this code but continues to don't work, Where i wrong?
Code: Select all
#include "ch.h"
#include "hal.h"
int latchPin = 4;
int clockPin = 5;
int dataPin = 7;
static uint8_t txbuf[1];
static uint8_t rxbuf[1];
#define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010)
static const SPIConfig spicfg = {
NULL,
GPIOA,
4, //GPIOA_PIN4
SPI_BaudRatePrescaler_8
};
static PWMConfig pwmcfg = {
1000000, // 1MHz PWM clock frequency
10000, // PWM period 10 milliseconds
NULL,
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
},
0,
0
};
int main(void) {
halInit();
chSysInit();
*******************************************************************
* ADAFRUIT MOTOR SHIELD
******************************/
int i;
// MC.ENABLE
pwmStart(&PWMD3, &pwmcfg);
palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2)); // PWM
palSetPadMode(GPIOB, 7, PAL_MODE_OUTPUT_PUSHPULL);
/* Initializes the SPI driver 1.*/
spiStart(&SPID1, &spicfg);
/* SPI1 I/O pins setup.*/
palSetPadMode(GPIOA, latchPin, PAL_MODE_ALTERNATE(5)); // SS = GPIOA_PIN4
palSetPadMode(GPIOA, clockPin, PAL_MODE_ALTERNATE(5)); // SCLK
palSetPadMode(GPIOA, dataPin, PAL_MODE_ALTERNATE(5)); // MOSI
palClearPad(GPIOB,7); // motorenable
//RESET
txbuf[0] = 0;
palClearPad(GPIOA, latchPin);
spiSelect(&SPID1); /* Slave Select assertion. */
spiExchange(&SPID1, 1,
txbuf, rxbuf); /* Atomic transfer operations. */
palSetPad(GPIOA, latchPin);
while (1) {
// RUN FORWARD (OUTPUT SHIFT REGISTER => Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 = 0 0 0 0 0 1 0 0)
pwmEnableChannel(&PWMD3, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 6000));
txbuf[0] = (uint8_t)4;
palClearPad(GPIOA, latchPin);
spiSelect(&SPID1); /* Slave Select assertion. */
spiExchange(&SPID1, 2,
txbuf, rxbuf); /* Atomic transfer operations. */
palSetPad(GPIOA, latchPin);
chThdSleepMilliseconds(200);
}
return 0;
}
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Adafruit motorshield port
The SS must be a GPIO not an alternate, also, use spiSelect() and spiUnselect() in order to control it.
Giovanni
Giovanni