Skip to content

Commit

Permalink
[stm32][lan9252]
Browse files Browse the repository at this point in the history
nucleo + mikroe
  • Loading branch information
alessiomargan committed Oct 9, 2024
1 parent 361b826 commit f3c4a00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
14 changes: 12 additions & 2 deletions soes/hal/advr_esc/esc_hw_lan9252_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,32 @@ inline void lan9252_write_32 (uint16_t address, uint32_t val)
cs_up();
}

#define FAST_READ
/* lan9252 single read */
inline uint32_t lan9252_read_32 (uint32_t address)
{
#ifdef FAST_READ
uint8_t data[4];
//uint8_t data[3];
#else
uint8_t data[3];
#endif
uint8_t result[4];

//data[0] = ESC_CMD_SERIAL_READ;
#ifdef FAST_READ
data[0] = ESC_CMD_FAST_READ;
#else
data[0] = ESC_CMD_SERIAL_READ;
#endif
data[1] = ((address >> 8) & 0xFF);
data[2] = (address & 0xFF);
#ifdef FAST_READ
data[3] = ESC_CMD_FAST_READ_DUMMY;
#endif

/* Select device. */
cs_dn();
/* Read data */
//spiWriteRead(&data, sizeof(data), &result, sizeof(result));
write (data, sizeof(data));
read (result, sizeof(result));
/* Un-select device. */
Expand Down
24 changes: 19 additions & 5 deletions soes/hal/advr_esc/hal_ec_STM32F4xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
*/
#include "stm32f4xx_hal.h"
#include "hal_ec.h"
//#include "pins.h"
#include "main.h"

#include <cc.h>

extern SPI_HandleTypeDef hspi4;
#define SPI_DFLT_TIMEOUT 100

inline void cs_up(void) { HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET); }
inline void cs_dn(void) { HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET); }
inline void cs_up(void) { HAL_GPIO_WritePin(ECAT_CS_GPIO_Port, ECAT_CS_Pin, GPIO_PIN_SET); }
inline void cs_dn(void) { HAL_GPIO_WritePin(ECAT_CS_GPIO_Port, ECAT_CS_Pin, GPIO_PIN_RESET); }

#if 0

inline uint8_t spi_write(uint8_t data) {
uint8_t rx_data;
HAL_StatusTypeDef ret;
ret = HAL_SPI_TransmitReceive(&hspi4, &data, &rx_data, 1, 100);
ret = HAL_SPI_TransmitReceive(&ecat_spi, &data, &rx_data, 1, SPI_DFLT_TIMEOUT);
//while( hspi3.State == HAL_SPI_STATE_BUSY );
if ( ret != HAL_OK ) {
DPRINT("%s errcode %d",__FUNCTION__,ret);
}
return rx_data;
}

#else

inline uint8_t spi_write(uint8_t data) {
// must be enabled in MX_SPI3_Init with __HAL_SPI_ENABLE(&hspi3);
ecat_spi.Instance->DR = data;
while ( ! __HAL_SPI_GET_FLAG(&ecat_spi, SPI_FLAG_RXNE) );
return ecat_spi.Instance->DR;
}


#endif

0 comments on commit f3c4a00

Please sign in to comment.