利用STM32硬件SPI 与TM7705 收发数据
/*****************************主程序**************************/
//PA2:CS
//PA5:SCK
//PA6:MISO
//PA7:MOSI
#include "stm32f10x.h"
#include "spi.h"
#include "stdio.h"
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void USART_Configuration(void);
u16 ReadTM7705(void);
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (unsigned char) ch);// USART1 可以换成 USART2 等
while (!(USART1->SR & USART_FLAG_TXE));
return (ch);
}
int GetKey (void)
{
while (!(USART1->SR & USART_FLAG_RXNE));
return ((int)(USART1->DR & 0x1FF));
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* 配置USART1波特率:9600;字长:8bit;停止位:1;奇偶校验:无;关闭硬件流控制模式;开启发送、接收功能 */
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1,USART_IT_RXNE, ENABLE);//使能串口1中断功能
USART_Cmd(USART1, ENABLE); //使