diff --git a/Drivers/DRV8301/drv8301.c b/Drivers/DRV8301/drv8301.c index d0e008ca..9bbbfb70 100644 --- a/Drivers/DRV8301/drv8301.c +++ b/Drivers/DRV8301/drv8301.c @@ -369,6 +369,16 @@ uint16_t DRV8301_readSpi(DRV8301_Handle handle, const DRV8301_RegName_e regName) uint16_t controlword = (uint16_t)DRV8301_buildCtrlWord(DRV8301_CtrlMode_Read, regName, 0); uint16_t recbuff = 0xbeef; HAL_SPI_Transmit(handle->spiHandle, (uint8_t*)(&controlword), 1, 1000); + + // Datasheet says you don't have to pulse the nCS between transfers, (16 clocks should commit the transfer) + // but for some reason you actually need to pulse it. + // Actuate chipselect + HAL_GPIO_WritePin(handle->nCSgpioHandle, handle->nCSgpioNumber, GPIO_PIN_SET); + osDelay(1); + // Actuate chipselect + HAL_GPIO_WritePin(handle->nCSgpioHandle, handle->nCSgpioNumber, GPIO_PIN_RESET); + osDelay(1); + HAL_SPI_TransmitReceive(handle->spiHandle, (uint8_t*)(&zerobuff), (uint8_t*)(&recbuff), 1, 1000); osDelay(1); @@ -685,24 +695,27 @@ void DRV8301_setupSpi(DRV8301_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars) DRV8301_RegName_e drvRegName; uint16_t drvDataNew; - - // Update Control Register 1 - drvRegName = DRV8301_RegName_Control_1; - drvDataNew = (DRV8301_PeakCurrent_0p25_A | \ - DRV8301_Reset_Normal | \ - DRV8301_PwmMode_Six_Inputs | \ - DRV8301_OcMode_CurrentLimit | \ - DRV8301_VdsLevel_0p730_V); - DRV8301_writeSpi(handle,drvRegName,drvDataNew); - - // Update Control Register 2 - drvRegName = DRV8301_RegName_Control_2; - drvDataNew = (DRV8301_OcTwMode_Both | \ - DRV8301_ShuntAmpGain_10VpV | \ - DRV8301_DcCalMode_Ch1_Load | \ - DRV8301_DcCalMode_Ch2_Load | \ - DRV8301_OcOffTimeMode_Normal); - DRV8301_writeSpi(handle,drvRegName,drvDataNew); +// Why impose hardcoded values? +// Defaults should be device defaults or application level specified. +// Setting other hardcoded here is just confusing! +// +// // Update Control Register 1 +// drvRegName = DRV8301_RegName_Control_1; +// drvDataNew = (DRV8301_PeakCurrent_0p25_A | \ +// DRV8301_Reset_Normal | \ +// DRV8301_PwmMode_Six_Inputs | \ +// DRV8301_OcMode_CurrentLimit | \ +// DRV8301_VdsLevel_0p730_V); +// DRV8301_writeSpi(handle,drvRegName,drvDataNew); +// +// // Update Control Register 2 +// drvRegName = DRV8301_RegName_Control_2; +// drvDataNew = (DRV8301_OcTwMode_Both | \ +// DRV8301_ShuntAmpGain_10VpV | \ +// DRV8301_DcCalMode_Ch1_Load | \ +// DRV8301_DcCalMode_Ch2_Load | \ +// DRV8301_OcOffTimeMode_Normal); +// DRV8301_writeSpi(handle,drvRegName,drvDataNew); Spi_8301_Vars->SndCmd = false; diff --git a/Odrive.ioc b/Odrive.ioc index fac74fd7..2244b172 100755 --- a/Odrive.ioc +++ b/Odrive.ioc @@ -334,8 +334,9 @@ PCC.Seq0=0 PCC.Series=STM32F4 PCC.Temperature=25 PCC.Vdd=3.3 -PD2.GPIOParameters=GPIO_Label +PD2.GPIOParameters=GPIO_Label,GPIO_PuPd PD2.GPIO_Label=nFAULT +PD2.GPIO_PuPd=GPIO_PULLUP PD2.Locked=true PD2.Signal=GPIO_Input PH0-OSC_IN.Mode=HSE-External-Oscillator @@ -463,9 +464,9 @@ SH.S_TIM8_CH2.0=TIM8_CH2,PWM Generation2 CH2 CH2N SH.S_TIM8_CH2.ConfNb=1 SH.S_TIM8_CH3.0=TIM8_CH3,PWM Generation3 CH3 CH3N SH.S_TIM8_CH3.ConfNb=1 -SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8 +SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 SPI3.CLKPhase=SPI_PHASE_2EDGE -SPI3.CalculateBaudRate=5.25 MBits/s +SPI3.CalculateBaudRate=2.625 MBits/s SPI3.DataSize=SPI_DATASIZE_16BIT SPI3.FirstBit=SPI_FIRSTBIT_MSB SPI3.IPParameters=Mode,CalculateBaudRate,BaudRatePrescaler,DataSize,FirstBit,CLKPhase diff --git a/Src/gpio.c b/Src/gpio.c index bcd18454..aecc78ef 100644 --- a/Src/gpio.c +++ b/Src/gpio.c @@ -102,7 +102,7 @@ void MX_GPIO_Init(void) /*Configure GPIO pin : PtPin */ GPIO_InitStruct.Pin = nFAULT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(nFAULT_GPIO_Port, &GPIO_InitStruct); } diff --git a/Src/spi.c b/Src/spi.c index 30e84fa4..32ec77a2 100644 --- a/Src/spi.c +++ b/Src/spi.c @@ -54,7 +54,7 @@ void MX_SPI3_Init(void) hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; hspi3.Init.CLKPhase = SPI_PHASE_2EDGE; hspi3.Init.NSS = SPI_NSS_SOFT; - hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi3.Init.TIMode = SPI_TIMODE_DISABLE; hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; diff --git a/Src/test.c b/Src/test.c index 76e98511..03e56f39 100644 --- a/Src/test.c +++ b/Src/test.c @@ -91,13 +91,11 @@ void test_DRV8301_setup() { //The DRV_8301 driver instance //DRV8301_Obj gate_drivers[NUM_MOTORS]; - while(1){ for (int i = 0; i < num_motors; ++i) { DRV8301_enable(&gate_drivers[i]); DRV8301_setupSpi(&gate_drivers[i], &gate_driver_regs[i]); osDelay(1000); } - } } void test_main(void) {