SPI1的MOSI怎么只有0.5V左右?

2019-07-21 01:44发布

现在在用SPI读ADXL345,发现开始读时,写入的第一个命令对不对都会输出正确的IDE5,然后就没有然后了 用示波器看波形MOSI不稳定,幅值不高,但有输出,波形好像和CLk端一样, 主要参考的是http://blog.sina.com.cn/s/blog_6754612e0101ag39.html 程序源码如下 [mw_shl_code=c,true]int main(void) { RCC_Configuration(); RTC_Configuration(); //???????±?±?? delay_init(72); LED_Init(); Sensor_Adxl = vect_new(3); GPIOA_USART1_Configuration(); USART1_Init(); // GPIO_SetBits(GPIOC,GPIO_Pin_4|GPIO_Pin_5); // GPIO_SetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1); GPIOA_SPI1_Configuration(); SPIx_Init(SPI1); Sensor_CSport_Init(); while(1) { write_byte(0x1E,0x00); delay_ms(100); write_byte(0x1F,0x00); delay_ms(100); write_byte(0x20,0x00); delay_ms(100); write_byte(0x2C,0x0A); delay_ms(100); write_byte(0x2D,0x00); delay_ms(100); write_byte(0x2E,0x80); delay_ms(100); write_byte(0x2F,0x00); delay_ms(100); write_byte(0x31,0x0B); delay_ms(100); while(1) { write_byte(0x33,0x08); delay_ms(100) a = read_byte(0x33); } } void GPIOA_SPI1_Configuration(void) { GPIO_InitTypeDef GPIOA_InitStructure; GPIOA_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIOA_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //???ì???? GPIOA_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIOA_InitStructure); GPIO_WriteBit(GPIOA,GPIO_Pin_4,Bit_SET);//??STM32?è?????÷?ú GPIOA_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 |GPIO_Pin_7; GPIOA_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???????ì???? GPIOA_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIOA_InitStructure); RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_SPI1, ENABLE ); } void SPIx_Init(SPI_TypeDef *SPIx) { // GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7); SPI1_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //?è??SPI???ò?ò?????ò??????????:SPI?è???????????ò?????¤ SPI1_InitStructure.SPI_Mode = SPI_Mode_Master; //?è??SPI?¤×÷????:?è?????÷SPI SPI1_InitStructure.SPI_DataSize = SPI_DataSize_16b; //?è??SPI???????ó??:SPI·???????8?????á?? SPI1_InitStructure.SPI_CPOL = SPI_CPOL_High; //???????®???±????????:?±???ü???? SPI1_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //?????????????????±???? SPI1_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS???????????¨NSS?????©?????í???¨????SSI???©???í:????NSS??????SSI?????? SPI1_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //?¨???¨?????¤·???????:?¨?????¤·???????256 SPI1_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //???¨??????????MSB??????LSB??????:??????????MSB?????? SPI1_InitStructure.SPI_CRCPolynomial = 7; //CRC?????????à?????¨?????© SPI_Init(SPIx, &SPI1_InitStructure); //?ù??SPI_InitStruct?????¨???????????????èSPIx?????÷ SPI_Cmd(SPIx, ENABLE); //????SPI???è // SPIx_ReadWriteByte(0xff); //???????? } void write_byte(u8 add,u8 val) { GPIO_ResetBits(GPIOB,GPIO_Pin_1); SPI_I2S_SendData(SPI1,add<<8|val); while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)==RESET); GPIO_SetBits(GPIOB,GPIO_Pin_1); SPI_I2S_ReceiveData(SPI1) & 0xff; } uint8_t read_byte(u8 add) { GPIO_ResetBits(GPIOA,GPIO_Pin_4); SPI_I2S_SendData(SPI1,(add|0x80)<<8|0x00); while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET); while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)==RESET); GPIO_SetBits(GPIOA,GPIO_Pin_4); return SPI_I2S_ReceiveData(SPI1)&0xff; }[/mw_shl_code]

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
正点原子
1楼-- · 2019-07-21 02:43
 精彩回答 2  元偷偷看……
litai11114
2楼-- · 2019-07-21 05:21
这个已经解决,是我选取的测试点的问题,这个测试点是通孔引出的,不过说来也是有点奇怪,这个点我测试过是和MOSI连通的,后来在同一根线上的的另一个测试点测试信号正常。。。。无语
姜波
3楼-- · 2019-07-21 11:16
你好,你的这个能正常读取adxl345的加速度值吗?我调了2天没调通,可以的话,发一份程序给我呗605574386@qq.com

一周热门 更多>