-
大小: 2KB文件類型: .c金幣: 1下載: 0 次發(fā)布日期: 2021-06-16
- 語言: 其他
- 標(biāo)簽: STM32??HMC5983??驅(qū)動(dòng)代碼??
資源簡介
基于STM32的HMC5983驅(qū)動(dòng)代碼,此處使用的是spi通信,通信部分自己寫。
代碼片段和文件信息
/*
*
*?1.調(diào)試開發(fā)參考hmc5983資料即可。
*
*/
#include?“stdio.h“
#include?“hmc5983.h“
#include?“stm32_Delay.h“
#include?“usb_lib.h“
#include?“string.h“
#define?Dummy_Byte???0x80????//虛假數(shù)據(jù)
//初始化hmc5983
void?hmc5983_init(void)
{
??u8?CheckID[]=“123“;
??GPIO_InitTypeDef?GPIO_InitStructure;
??spi2_init();
??RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB?ENABLE);
??GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_9?|?GPIO_Pin_12;
??GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_PP;
??GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
??GPIO_Init(GPIOB?&GPIO_InitStructure);
??GPIO_ResetBits(GPIOBGPIO_Pin_9);
??hmc5983_ReadBuf(HMC5983_IDA_REGCheckID3);?//讀取機(jī)器ID進(jìn)而判斷芯片是否準(zhǔn)備ok
??if(strncmp((char*)CheckIDHMC5983_ID3)!=0)
??{
#ifdef?MY_DEBUG
????printf(“Didn‘t?check?to?HMC5983!?ReadID:%s\n“CheckID);
#endif
??}
??else
??{
#ifdef?MY_DEBUG
????printf(“The?HMC5983?is?ready!\n“);
#endif
????hmc5983_WriteByte(HMC5983_CONF_REG_A0x14);????//正常測(cè)量,1次平均?30HZ
????hmc5983_WriteByte(HMC5983_CONF_REG_B0x30);????//±2.5Ga
????hmc5983_WriteByte(HMC5983_MODE_REG??0x01);????//
評(píng)論
共有 條評(píng)論