سلام به همگی
عیدتون مبارک
من یک برنامه با استفاده از توایع CMSIS برای برقرار ارتباط با ماژول HMC5883L نشوم ولی درست کار نمیکنه
و اطلاعات دریافتی همیشه صفر هست
به نظرتون مشکل از کجاست؟
اینهم فایلهای سورس و هدر
HMC5885L.C
HMC5885L.h
و این هم
Main.c
کل پروژه رو هم میتونید از ادرس زیر دانلود کنید
http://s6.picofile.com/file/8178718434/hmc.rar.html
عیدتون مبارک
من یک برنامه با استفاده از توایع CMSIS برای برقرار ارتباط با ماژول HMC5883L نشوم ولی درست کار نمیکنه
و اطلاعات دریافتی همیشه صفر هست
به نظرتون مشکل از کجاست؟
اینهم فایلهای سورس و هدر
HMC5885L.C
کد:
#include "HMC5883L.h" #include "lpc17xx.h" #include "lpc17xx_i2c.h" #include "lpc17xx_pinsel.h" #include "lpc17xx_uart.h" #include "debug_frmwrk.h" //=================================================================================================================================== //Initialize HMC5883L I2C Port //=================================================================================================================================== void HMC5883L_I2C_Init(void){ PINSEL_CFG_Type HMC5883L_PinCfg; HMC5883L_PinCfg.OpenDrain = 0; HMC5883L_PinCfg.Pinmode = 0; #if ((HMC5883L_I2C == 0)) HMC5883L_PinCfg.Funcnum = 1; HMC5883L_PinCfg.Pinnum = 27; HMC5883L_PinCfg.Portnum = 0; PINSEL_ConfigPin(&HMC5883L_PinCfg); HMC5883L_PinCfg.Pinnum = 28; PINSEL_ConfigPin(&HMC5883L_PinCfg); #endif #if ((HMC5883L_I2C == 2)) HMC5883L_PinCfg.Funcnum = 2; HMC5883L_PinCfg.Pinnum = 10; HMC5883L_PinCfg.Portnum = 0; PINSEL_ConfigPin(&HMC5883L_PinCfg); HMC5883L_PinCfg.Pinnum = 11; PINSEL_ConfigPin(&HMC5883L_PinCfg); #endif I2C_Init(I2CX, HMC5883L_I2C_CLK); I2C_Cmd(I2CX, ENABLE); LPC_PINCON->PINMODE_OD0 = 0x00000C00; }
کد:
#ifndef HMC5883L_H_ #define HMC5883L_H_ #define HMC5883L_I2C 2 #if (HMC5883L_I2C == 0) #define I2CX LPC_I2C0 #elif(HMC5883L_I2C == 2) #define I2CX LPC_I2C2 #else #error "Master I2C device not defined!" #endif #define HMC5883L_I2C_CLK 100000 #define HMC5883L_ADDRESS 0x0C #define CFG_REG_A 0x00 // READ/WRITE #define CFG_REG_B 0x01 // READ/WRITE #define MODE_REG 0x02 // READ/WRITE #define OUT_X_A 0x03 // READ Data Output X Registers A and B (A-> MSB) | (B-> LSB) #define OUT_X_B 0x04 // READ Data Output X Registers A and B (A-> MSB) | (B-> LSB) #define OUT_Y_A 0x05 // READ Data Output Y Registers A and B (A-> MSB) | (B-> LSB) #define OUT_Y_B 0x06 // READ Data Output Y Registers A and B (A-> MSB) | (B-> LSB) #define OUT_Z_A 0x07 // READ Data Output Z Registers A and B (A-> MSB) | (B-> LSB) #define OUT_Z_B 0x08 // READ Data Output Z Registers A and B (A-> MSB) | (B-> LSB) #define STATUS_REG 0x09 // READ #define IDFC_REG_A 0x0A // READ #define IDFC_REG_B 0x0B // READ #define IDFC_REG_C 0x0C // READ //#########################==========================================================####### //Configuration Register A //#########################==========================================================####### //Select number of samples averaged (1 to 8) per measurement output(MA1 to MA0) //00 = 1(Default); 01 = 2; 10 = 4; 11 = 8 #define samples_averaged 0x00 //Data Output Rate Bits. These bits set the rate at which data //is written to all three data output registers (DO2 to DO0) // DO2 DO1 DO0 Typical Data Output Rate (Hz) // 0 0 0 0.75 // 0 0 1 1.5 // 0 1 0 3 // 0 1 1 7.5 // 1 0 0 15 (Default) // 1 0 1 30 // 1 1 0 75 // 1 1 1 Reserved #define Data_Output_Rate 0x10 // MS1 MS0 Measurement Mode //==========================================================================================================| // 0 0 Normal measurement configuration (Default). In normal measurement | // configuration the device follows normal measurement flow. The positive and | // negative pins of the resistive load are left floating and high impedance. | // 0x00 | //==========================================================================================================| // 0 1 Positive bias configuration for X, Y, and Z axes. In this configuration, a positive | // current is forced across the resistive load for all three axes. | // 0x01 | //==========================================================================================================| // 1 0 Negative bias configuration for X, Y and Z axes. In this configuration, a negative | // current is forced across the resistive load for all three axes.. | // 0x02 | //==========================================================================================================| // 1 1 This configuration is reserved | // 0x03 | //==========================================================================================================| #define Measurement_Mode 0x00 //#########################==========================================================####### //Configuration Register B //#########################==========================================================####### // GN2 | GN1 | GN0 Recommended Gain Digital Hex // | | Sensor Field (LSb/Gauss) Resolution // | | Range (mG/LSb) // | | // 0 | 0 | 0 ± 0.88 Ga 1370 0.73 0x00 // 0 | 0 | 1 ± 1.3 Ga 1090 (default ) 0.92 0x20 // 0 | 1 | 0 ± 1.9 Ga 820 1.22 0x40 // 0 | 1 | 1 ± 2.5 Ga 660 1.52 0x60 // 1 | 0 | 0 ± 4.0 Ga 440 2.27 0x80 // 1 | 0 | 1 ± 4.7 Ga 390 2.56 0xA0 // 1 | 1 | 0 ± 5.6 Ga 330 3.03 0xC0 // 1 | 1 | 1 ± 8.1 Ga 230 4.35 0xE0 #define Gain_Configuration 0x20 //Other bits must be cleared for correct operation //#########################==========================================================####### //Mode Register //#########################==========================================================####### //HS -> Set this pin to enable High Speed I2C, 3400kHz. (0x80 = High Speed) | (0x00 = Low Speed) #define HS 0x00 //Mode Select // MD1 MD0 HEX // 0 0 Continuous-Measurement Mode. (0x00) // 0 1 Single-Measurement Mode (Default). (0x01) // 1 0 Idle Mode. Device is placed in idle mode. (0x02) // 1 1 Idle Mode. Device is placed in idle mode. (0x03) #define Mode_Select 0x01 void HMC5883L_I2C_Init(void); unsigned char HMC5883L_Read(unsigned char reg); #endif
و این هم
Main.c
کد:
#include "lpc17xx.h" #include "LPC17xx.h" #include <stdio.h> #include "lpc17xx_gpio.h" #include "lpc17xx_clkpwr.h" #include "lpc17xx_i2c.h" #include "lpc17xx_libcfg_default.h" #define SystemCoreClock 100000000 #include "delay.h" #include "lpc17xx_uart.h" #include "lpc17xx_pinsel.h" #include "debug_frmwrk.h" #include "HMC5883L.h" int main(void){ uint8_t out; HMC5883L_I2C_Init(); //HMC5883L_Init(); debug_frmwrk_init(); UARTPuts(LPC_UART0, "This is a test "); while(1){ out = HMC5883L_Read(IDFC_REG_B); out = HMC5883L_Read(IDFC_REG_A); out = HMC5883L_Read(OUT_X_A); } }
کل پروژه رو هم میتونید از ادرس زیر دانلود کنید
http://s6.picofile.com/file/8178718434/hmc.rar.html
دیدگاه