TA的每日心情 | 开心 2017-1-11 04:03 |
---|
签到天数: 3 天 连续签到: 1 天 [LV.2]偶尔看看I
|
前言
承接pmodnav-2 ,pmodnav上有两个芯片。
lsm9ds1 和lps25hb.这两个芯片。我主要用的lsm9ds1.lps25hb通信和lsm9ds1都一样spi 4-wire,自己可以改
注意下边这个
我没用到中断,我用的polled实现,这里的中断信号我全部接入了gpio的input接口
// 0 cs_A/G// 1 input// 2 input// 3 cs_M// 4 cs_ALT// first we choice 0x18
软件部分
过多废话不多说了。
这是实现对WHO AM I 寄存器的读出。debug模式可以看见readbuffer。我没有打印。
/* * * * ------------------------------------------------ * | UART TYPE BAUD RATE | * ------------------------------------------------ * uartns550 9600 * uartlite Configurable only in HW design * ps7_uart 115200 (configured by bootrom/bsp) */#include <stdio.h>#include "platform.h"#include "xparameters.h"#include "XGpio.h"#include "XSpi.h"#include "xintc.h"#include "xil_exception.h"#include "xstatus.h"#include "xil_printf.h"//DEFINE SOME NAME#define NAV_GPIO XPAR_MY_GPIO_DEVICE_ID#define NAV_SPI XPAR_MY_SPI_DEVICE_ID#define NAV_INTC XPAR_INTC_0_DEVICE_ID#define NAV_SPI_IRPT_INTR XPAR_INTC_0_SPI_0_VEC_ID#define INTC XIntc#define INTC_HANDLER XIntc_InterruptHandler#define BUFFER_SIZE 12typedef u8 DataBuffer[BUFFER_SIZE];//FUNCTION u8 ReadBuffer[BUFFER_SIZE];u8 WriteBuffer[BUFFER_SIZE]; int init_lsm9ds1(int* dat);int init_spi();int gpio_init(); //initial ipXGpio my_gpio;XSpi my_spi;//registersvolatile int TransferInProgress;int Error;u8 config[2];int main(){ int data; init_platform(); print("Nav demo by hahahuan!\n\r"); int status=gpio_init(); if (status != XST_SUCCESS) { return XST_FAILURE; } print("GPIO init finish!\n\r"); status=init_spi(); if (status != XST_SUCCESS) { return XST_FAILURE; } print("spi init finish\n\r"); print("read WHO I AM REGISTER!"); status= init_lsm9ds1(&data); if (status != XST_SUCCESS) { return XST_FAILURE; } print("read finish"); cleanup_platform(); return 0;}int gpio_init(){ int status = XGpio_Initialize(&my_gpio,NAV_GPIO); if (status != XST_SUCCESS) { return XST_FAILURE; } XGpio_SetDataDirection(&my_gpio, 1, 0x06);//00110 direction return XST_SUCCESS;}int init_spi(){ XSpi_Config *cfg; cfg=XSpi_LookupConfig(NAV_SPI); if(cfg==NULL){ return XST_FAILURE; } int status; status=XSpi_CfgInitialize(&my_spi, cfg,cfg->BaseAddress); if(status!=XST_SUCCESS){ return XST_FAILURE; } status = XSpi_SelfTest(&my_spi); if (status != XST_SUCCESS) { return XST_FAILURE; } if ((&my_spi)->SpiMode != XSP_STANDARD_MODE) { return XST_FAILURE; } status = XSpi_SetOptions(&my_spi, XSP_MASTER_OPTION|XSP_MANUAL_SSELECT_OPTION|XSP_CLK_ACTIVE_LOW_OPTION|XSP_CLK_PHASE_1_OPTION); if (status != XST_SUCCESS) { return XST_FAILURE; } status =XSpi_SetSlaveSelect(&my_spi,0x01); if (status != XST_SUCCESS) { return XST_FAILURE; } XSpi_Start(&my_spi); XSpi_IntrGlobalDisable(&my_spi); return XST_SUCCESS;}int init_lsm9ds1(int* dat){ // 0 cs_A/G // 1 input // 2 input // 3 cs_M // 4 cs_ALT // first we choice XGpio_DiscreteWrite(&my_gpio, 1, 0x18); //u32 data= XGpio_DiscreteRead(&my_gpio, 1); WriteBuffer[0]=(u8)(0x8f);// 10001111 who am i XSpi_Transfer(&my_spi, WriteBuffer, ReadBuffer, 2); XGpio_DiscreteWrite(&my_gpio, 1, 0x19); *dat=ReadBuffer[2]; return XST_SUCCESS;}结果
还有
还有
完结
整个驱动PmodNav就完成了。我暂时没用到他做mems。
对于LSM9DS1的工作模式和一些fifo使用功能bass什么的。还有校准什么的。 没有过多弄。
历史
V 0.1 第一次创建
V 0.11 修改ReadBuffer[2]改为[1] |
|