XS128 SPI communicate with MMA7455

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

XS128 SPI communicate with MMA7455

1,942件の閲覧回数
KiraVerSace
Contributor I
Hi, first allow me to apologize if my english is not really good, it is not my native language. I'm a student from China,I hope here somebody could help me, I spend a week with mma7455,but I can not find the question. Here is the init code that it generates #define MMA_CS_D DDRM_DDRM3 #define MMA_MISO_D DDRM_DDRM2 #define MMA_MOSI_D DDRM_DDRM4 #define MMA_SCK_D DDRM_DDRM5 #define MMA_INT1_D DDRT_DDRT6 #define MMA_INT2_D DDRT_DDRT5 #define MMA_CS PTM_PTM3 #define MMA_MISO PTM_PTM2 #define MMA_MOSI PTM_PTM4 #define MMA_SCK PTM_PTM5 #define MMA_INT1 PTT_PTT6 #define MMA_INT2 PTT_PTT5 void mma7455_Init(void){ MODRR_MODRR4=1; //Module Routing Register (MODRR) 设置引脚的第二功能 启用PM2345 MMA_CS_D=1; //必须初始化IO方向 MMA_MISO_D=0; MMA_MOSI_D=1; MMA_SCK_D=1; MMA_CS=1; //CS=1 SPI0CR1=0x5e; //SPI初始化 0101 0000 中断禁止 主机模式 时钟空闲为高 先发最高位 SPI0CR2=0x10; //ss 引脚 受MODFEN 控制 SPI0BR=0x06; //SPI 128分频 16/128MHz SPI_Write_Reg_mma7455(0x16,0x05); //SPI四线模式 不自检 范围2g 测量模式 SPI_Write_Reg_mma7455(0x0D,0x80); //禁止IIC功能 } unsigned int SPI_Read_Reg_mma7455(unsigned int uiReg){ unsigned int uiTemp=0; MMA_CS=0; //CS=0 uiTemp=SPI0DRL; while (!SPI0SR_SPTEF); //判断发送寄存器是空的 SPI0DRL= ((uiReg &0x3F)<<1); //向寄存器地址写 读的命令 while(!SPI0SR_SPIF); //写完读取从机的寄存器的指令之后 等待从机反馈数据 uiTemp=SPI0DRL; //读取MMA7455反馈的数据 SPI0DRL=0xff; //主机产生8个时钟信号,MMA7455返回 数据 while(!SPI0SR_SPIF); uiTemp=SPI0DRL; MMA_CS=1; //CS=1 return (uiTemp); } void SPI_Write_Reg_mma7455(unsigned int uiReg,unsigned int uiValue){ unsigned int uiTemp=0; MMA_CS=0; //CS=0 while (!SPI0SR_SPTEF); //判断发送寄存器是空的 SPI0DRL=(((uiReg &0x3F)<<1)|0x80); //选择像哪个寄存器写 指令 while (!SPI0SR_SPIF); //判断SPI0IF是否产生中断 uiTemp=SPI0DRL; while (!SPI0SR_SPTEF); SPI0DRL=uiValue; while(!SPI0SR_SPIF); uiTemp=SPI0DRL; MMA_CS=1; //CS=1 }
ラベル(1)
0 件の賞賛
返信
2 返答(返信)

886件の閲覧回数
liushichang
Contributor I

你用中文注释让老外怎么读啊,而且还不隔行显示,全粘在一起。发到 lsc0000@126.com,我给你看看

 

0 件の賞賛
返信

886件の閲覧回数
bigmac
Specialist III

Hello, and welcome to the forum.

 

The primary reason you have not yet received a response to your post is that the code you presented is virtually unreadable.  Comments in Chinese will also not be helpful to non-Chinese readers.  I would suggest that you use the code entry window to present your code, and also provide translation of the various comments.  It may also be useful for you to describe in more detail, the nature of the SPI problem you are experiencing.

 

Regards,

Mac

0 件の賞賛
返信