本文整理汇总了C++中HAL_SPI_Transmit函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_SPI_Transmit函数的具体用法?C++ HAL_SPI_Transmit怎么用?C++ HAL_SPI_Transmit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_SPI_Transmit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bstdr_burst_read
/*!
* @brief Generic burst read
*
* @param [out] dev_id I2C address, SPI chip select or user desired identifier
*
* @return Zero if successful, otherwise an error code
*/
bstdr_ret_t bstdr_burst_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint32_t len){
uint8_t spi_address_cmd = 0x80;
HAL_StatusTypeDef hal_res;
/**< Burst read code comes here */
if (dev_id == 0x1A) //ACC sensor
{
//SPI chip select
HAL_GPIO_WritePin(GPIOA, ACC_CS_Pin, GPIO_PIN_RESET);
//SPI transcation begin
spi_address_cmd |= reg_addr;
hal_res = HAL_SPI_Transmit(&hspi3, &spi_address_cmd, 1, 500);
hal_res = HAL_SPI_Receive(&hspi3, reg_data, len, 500);
//SPI transcation end
//SPI chip deselecet
HAL_GPIO_WritePin(GPIOA, ACC_CS_Pin, GPIO_PIN_SET);
}
else if (dev_id == 0x1B) //Gyro sensor
{
//SPI chip select
HAL_GPIO_WritePin(GPIOA, GYRO_CS_Pin, GPIO_PIN_RESET);
//SPI transcation begin
spi_address_cmd |= reg_addr;
hal_res = HAL_SPI_Transmit(&hspi3, &spi_address_cmd, 1, 500);
hal_res = HAL_SPI_Receive(&hspi3, reg_data, len, 500);
//SPI transcation end
//SPI chip deselecet
HAL_GPIO_WritePin(GPIOA, GYRO_CS_Pin, GPIO_PIN_SET);
}
else
{
return BSTDR_E_CON_ERROR;
}
return BSTDR_OK;
}
示例2: Flash_Program
void Flash_Program(uint32_t Addr, uint8_t *Data, uint16_t Size)
{
uint8_t cmd[4];
uint8_t i;
//Check if Erase/Program in progress
Flash_WaitBusy();
// Enable write
Flash_Command(s_FLASH__CMD_WR_ENABLE);
s_FLASH__SELECT();
// Prepare command
cmd[0] = s_FLASH__CMD_PAGE_PROGRAM;
cmd[1] = (uint8_t)((Addr>>16) & 0xFF);
cmd[2] = (uint8_t)((Addr>>8) & 0xFF);
cmd[3] = (uint8_t)(Addr & 0xFF);
// Send 'Program Page' instruction and address
HAL_SPI_Transmit(&g_Flash_SpiHandle, cmd, 4, 1000);
// Send data
HAL_SPI_Transmit(&g_Flash_SpiHandle, Data, Size, 1000);
s_FLASH__DESELECT();
}
示例3: vfd_write_display_flag
void vfd_write_display_flag(uint8_t addr, uint8_t flag) {
addr += 0xC0;
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, &addr, 1, 1000);
HAL_SPI_Transmit(&hspi1, &flag, 1, 1000);
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET);
}
示例4: INVMPU_WriteBytes
/**
* @brief Write MPU60x0 register
* @param addr: register address, data: data to write
* @retval None
*/
u8 INVMPU_WriteBytes(u8 addr, u16 len, const u8* data)
{
MPU_SPISelect();
if(HAL_SPI_Transmit(MPU_SPI, &addr, 1, 5) == HAL_OK)
{
HAL_SPI_Transmit(MPU_SPI, (u8*)data, len, 5);
}
MPU_SPIDeselect();
return 0;
}
示例5: MPU9255_Write_Reg
//SPIд¼Ä´æÆ÷
//reg:Ö¸¶¨µÄ¼Ä´æÆ÷µØÖ·
//value:дÈëµÄÖµ
uint8_t MPU9255_Write_Reg(uint8_t reg,uint8_t value)
{
uint8_t status;
SPI_MPU9255_CS_L; //ʹÄÜSPI´«Êä
status = HAL_SPI_Transmit(&hspi1, ®, 1, 0xFFFF);
status = HAL_SPI_Transmit(&hspi1, &value, 1, 0xFFFF);
SPI_MPU9255_CS_H; //½ûÖ¹MPU9255
Delay(0xFFF);
return(status); //·µ»Ø״ֵ̬
}
示例6: spiTransfer
bool spiTransfer(SPI_TypeDef *instance, uint8_t *out, const uint8_t *in, int len)
{
SPIDevice device = spiDeviceByInstance(instance);
HAL_StatusTypeDef status;
#define SPI_DEFAULT_TIMEOUT 10
if(!out) // Tx only
{
status = HAL_SPI_Transmit(&spiHardwareMap[device].hspi, (uint8_t *)in, len, SPI_DEFAULT_TIMEOUT);
}
else if(!in) // Rx only
{
status = HAL_SPI_Receive(&spiHardwareMap[device].hspi, out, len, SPI_DEFAULT_TIMEOUT);
}
else // Tx and Rx
{
status = HAL_SPI_TransmitReceive(&spiHardwareMap[device].hspi, (uint8_t *)in, out, len, SPI_DEFAULT_TIMEOUT);
}
if( status != HAL_OK)
spiTimeoutUserCallback(instance);
return true;
}
示例7: ds3234_get_reg
void ds3234_get_reg(uint8_t addr, uint8_t* val) {
addr &= 0x7F;
HAL_GPIO_WritePin(DS3234_CS_GPIO_Port, DS3234_CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi2, &addr, 1, 1000);
HAL_SPI_Receive(&hspi2, val, 1, 1000);
HAL_GPIO_WritePin(DS3234_CS_GPIO_Port, DS3234_CS_Pin, GPIO_PIN_SET);
}
示例8: DRV8301_readSpi
uint16_t DRV8301_readSpi(DRV8301_Handle handle, const DRV8301_RegName_e regName)
{
// Actuate chipselect
HAL_GPIO_WritePin(handle->nCSgpioHandle, handle->nCSgpioNumber, GPIO_PIN_RESET);
osDelay(1);
// Do blocking read
uint16_t zerobuff = 0;
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);
// Actuate chipselect
HAL_GPIO_WritePin(handle->nCSgpioHandle, handle->nCSgpioNumber, GPIO_PIN_SET);
osDelay(1);
assert(recbuff != 0xbeef);
return(recbuff & DRV8301_DATA_MASK);
} // end of DRV8301_readSpi() function
示例9: spi_rw
static sint8 spi_rw(uint8 *tx_buf, uint8 *rx_buf, uint16 u16Sz)
{
sint8 result = M2M_SUCCESS;
// Start SPI transfer
// TODO: Use DMA
__disable_irq();
SPI_ASSERT_CS();
if (tx_buf != 0) {
if (HAL_SPI_Transmit(&SPI_HANDLE, tx_buf, u16Sz, SPI_TIMEOUT) != HAL_OK) {
result = M2M_ERR_BUS_FAIL;
}
} else {
tx_buf = rx_buf;
memset(tx_buf, 0, u16Sz);
if (HAL_SPI_TransmitReceive(&SPI_HANDLE, tx_buf, rx_buf, u16Sz, SPI_TIMEOUT) != HAL_OK) {
result = M2M_ERR_BUS_FAIL;
}
}
SPI_DEASSERT_CS();
__enable_irq();
return result;
}
示例10: spi_test
static int spi_test(void) {
uint8_t res = 0;
uint8_t data = 0x23;
printf("SPI test\n");
while(1) {
spi_delay(1000000);
res = 0;
// sync
spi_sync();
printf(">> synchronized\n");
// data from master
if (HAL_SPI_Receive(&SpiHandle, &res, 1, SPI_TIMEOUT_MAX) != HAL_OK) {
printf("HAL_SPI_Receive error 1\n");
return -1;
}
if (res != 0x57) {
printf("HAL_SPI_Receive recieved not 0x57 but %x\n", res);
}
// request data
if (HAL_SPI_Transmit(&SpiHandle, &data, 1, SPI_TIMEOUT_MAX) != HAL_OK) {
printf("HAL SPI Transmit error\n");
return -1;
}
}
return 0;
}
示例11: MAX_Init
void MAX_Init(){
// MX_SPI2_Init();
// __HAL_SPI_ENABLE(&hspi2);
#if 0
dataOut[0] = (17<<3) | 2;
dataOut[1] = 0x10;
cs_low;
HAL_SPI_Transmit(&hspi2, dataOut, 2, 1000);
cs_high;
Hwreg(rUSBIEN, bmOSCOKIE);
Hrreg(rUSBIEN);
Hrreg(18<<3);
#endif
// MAX3421E: Full duplex mode, INTLEVEL=0, POSINT=1 for pos edge interrupt pin
Hwreg(rPINCTL,(bmFDUPSPI|bmPOSINT));
MAX_Reset();
// MAX3421E EVB
Hwreg(rIOPINS1,0x00); // seven-segs off
Hwreg(rIOPINS2,0x00); // and Vbus OFF (in case something already plugged in)
HAL_Delay(200);
VBUS_ON;
}
示例12: writeReg
static void writeReg(SPI_HandleTypeDef *const handle, const uint8_t &adr, const uint8_t val) {
// HAL_I2C_Mem_Write(handle, 0x82, adr, 1, (uint8_t*)&val, 1, 0x0F);
uint8_t buff[] = { adr, val };
BSP_Gpio_SetPin(GPIO_MEMS_CS, false);
HAL_SPI_Transmit(handle, buff, 2, 0x0F);
BSP_Gpio_SetPin(GPIO_MEMS_CS, true);
}
示例13: LCD_WR_DATA8
void LCD_WR_DATA8(uint8_t da) //写8位数据
{
SPILCD_CS_RESET; //LCD_CS=0
SPILCD_RS_SET;
HAL_SPI_Transmit(&hspi1, &da, 1 , 100);
SPILCD_CS_SET; //LCD_CS=1
}
示例14: send_SPI
// I/O
void send_SPI(uint8_t * inBuf, uint8_t inLength, uint8_t * outBuf, uint8_t outLength)
{
HAL_GPIO_WritePin(COMP_CS_P, COMP_CS, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, outBuf, outLength, 1000);
HAL_SPI_Receive(&hspi1, inBuf, inLength, 1000);
HAL_GPIO_WritePin(COMP_CS_P, COMP_CS, GPIO_PIN_SET);
}
示例15: HAL_SPI_TransmitNew
HAL_StatusTypeDef HAL_SPI_TransmitNew(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout){
HAL_StatusTypeDef returnvar;
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_8,GPIO_PIN_RESET);
returnvar = HAL_SPI_Transmit(hspi,pData,Size,Timeout);
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_8,GPIO_PIN_SET);
return returnvar;
}