欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
我想實現STM32F4驅動AD7705的功能,代碼如下,編譯沒有錯誤,求大佬幫忙看看
[打印本頁]
作者:
有沒有魚干
時間:
2020-7-13 16:48
標題:
我想實現STM32F4驅動AD7705的功能,代碼如下,編譯沒有錯誤,求大佬幫忙看看
#include "stm32f4xx.h"
#include "usart.h"
#include "lcd.h"
#include "delay.h"
#include "led.h"
#include "stdio.h"
void RCC_Configuration(void);
void GPIO_Configuration(void);
u16 SPIx_ReadWriteByte(u16 TxData);
void SPIx_Init(void);
u16 ReadTM7705(void);
uint8_t TM7705_Recive8Bit(void);
void TM7705_Send8Bit(uint8_t _data);
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART1 Rx (PB.8) as input floating busy busy DRDY */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/********ÅäÖÃÏμí3ê±Öó,ê1Äü¸÷íaéèê±Öó***********/
void RCC_Configuration(void)
{
SystemInit();
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOA, ENABLE );
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1| RCC_APB2Periph_USART1, ENABLE);
}
/********TM77053õê¼»ˉoˉêy***********/
void TM7705_Init(void)
{
unsigned char i ;
for(i = 0; i < 100; i++)
{
SPIx_ReadWriteByte(0xFF);
}
SPIx_ReadWriteByte(0x20) ;
Delay(800);
SPIx_ReadWriteByte(0x02) ;
Delay(800);
SPIx_ReadWriteByte(0x10) ;
Delay(800);
SPIx_ReadWriteByte(0x44) ;
Delay(8000);
}
/********¶á16λêy¾Y************/
u16 ReadTM7705_16BitValue(void)
{
//unsigned long
u16 DataL = 0;
// unsigned long
u16 DataH = 0;
//unsigned long
u16 Ret = 0;
DataH =SPIx_ReadWriteByte(0xff);
delay_ms(10);
DataH = DataH << 8;
DataL = SPIx_ReadWriteByte(0xff);
delay_ms(10);
Ret = DataH | DataL;
return(Ret) ;
}
/********¶áè¡AD7705μúò»í¨μàêy¾Y************/
u16 ReadTM7705(void)
{
u16 Ret = 0;
SPIx_ReadWriteByte(0x38) ;
while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10==1))
{
;
}
Ret = ReadTM7705_16BitValue();
delay_ms(100);
return Ret;
}
/****************************SPI3õê¼»ˉ*************************/
void SPIx_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOA, ENABLE);//
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource3,GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource4,GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource5,GPIO_AF_SPI1);
/* Configure SPI1 pins: SCK, MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP ;
//GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure I/O for Flash Chip select */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //SPI CS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //¸′óÃíÆíìêä3ö
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP ;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Deselect the FLASH: Chip Select high */
GPIO_SetBits(GPIOA,GPIO_Pin_9);
// GPIO_SetBits(GPIOA,GPIO_Pin_10);
SPI_Cmd(SPI1, DISABLE);
/* SPI1 configuration */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
//SPI1->CR1|=1<<6;
/* Enable SPI1 */
SPI_Cmd(SPI1, ENABLE);
SPIx_ReadWriteByte(0xff);
}
u16 SPIx_ReadWriteByte(u16 TxData)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_9);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); //
/* Send byte through the SPI1 peripheral */
SPI_I2S_SendData(SPI1, TxData)
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); //
/* Return the byte read from the SPI bus */
GPIO_SetBits(GPIOA,GPIO_Pin_9);
return SPI_I2S_ReceiveData(SPI2); //·μ»Øí¨1ySPIx×î½ü½óêÕμÄêy¾Y
}
/********Ö÷oˉêy************/
int main(void)
{
u16 adcx;
float temp;
RCC_Configuration();
GPIO_Configuration();
uart_init(76800);
delay_init(168);
LCD_Init();
LED_Init();
SPIx_Init();
TM7705_Init();
POINT_COLOR=BLUE;
LCD_ShowString(30,110,200,16,16,"ADC_CH1_VAL:");
LCD_ShowString(30,170,200,16,16,"ADC_CH1_VOLL:0.0000V");
while(1)
{
//delay_ms(50);
adcx = ReadTM7705();
LCD_ShowxNum(134,110,adcx,5,16,0);
temp=(float)adcx*(3.0/65535);
adcx=temp;
LCD_ShowxNum(134,170,adcx,1,16,0);
temp-=adcx;
temp*=10000;
LCD_ShowxNum(150,170,temp,4,16,0X80);
LED0=!LED0;
delay_ms(200);
}
}
LCD顯示出來的一直是最大值65535。。。。應該是數據異常。。。。。。debug的時候SPI里面數據寄存器的數值好像不太正常。。。。求大神幫幫忙。。謝謝啦!
作者:
f556
時間:
2020-7-14 14:55
把AD7705的輸入端短接、把PGA調到最小試試,其它可能的問題也會是SPI程序錯誤
作者:
有沒有魚干
時間:
2020-7-14 16:50
f556 發表于 2020-7-14 14:55
把AD7705的輸入端短接、把PGA調到最小試試,其它可能的問題也會是SPI程序錯誤
短接了還是跟原來一樣。。。。。請問PGA是怎么調的。。。
作者:
樂兒翅
時間:
2020-7-28 10:19
、PGA相關的參數 bitmap_merge_area_size -->位圖合并區分配的值 create_bitmap_area_size -->創建位圖分配的值 hash_area_size -->主要用于hash join時分配的大小 sort_area_size -->排序所用的內存總量,影響one-pass,multi-pass,optimal sort_area_retained_size -->排序后在內存中保存排序信息的內存總量 這幾個參數在Oracle 9i之前被使用,在Oracle 9i可以對這幾個參數進行手動分配,亦可以由系統自動分配。
作者:
Roy-2010
時間:
2020-8-8 17:17
一邊調一邊看。
作者:
世界太小_
時間:
2020-8-11 10:15
我只能說,你等著吧
就放一個工程出來,也不知道具體原因出在哪里,就等著別人給你解決
老鐵,你應該有一套自己的思路,然后哪里出了問題,別人好針對性的給你解決思路
比如說LCD,你直接說顯示不了,別人怎幫你
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1