请添加图片描述

所有资源导航

其他资料目录 直戳跳转

一、资源说明

单片机型号 测试条件 模块名称 代码功能
STC89C52RC 晶振11.0592M TF卡模块 STC89C52RC驱动TF卡模块 串口与OLED0.96双显示
STM32F103C8T6 晶振8M/系统时钟72M TF卡模块 STM32F103C8T6驱动TF卡模块 串口与OLED0.96双显示

二、基本参数

参数

请添加图片描述

引脚说明

TF卡模块 引脚说明
VCC 正极 5V供电
GND GND 电源负极
MISO SPI总线 主机输入从机输出引脚
MOSI SPI总线 主机输出从机输入引脚
SCK SPI总线 时钟引脚
CS 片选信号脚

三、驱动说明

时序

SPI时序

对应程序:

/**
  * @brief  SPI_SD引脚初始化
  * @param  无
  * @retval 无
  */
void SPI_SD_Init(void)
{
 
  GPIO_InitTypeDef GPIO_InitStructure;
	
	/* 使能SPI引脚相关的时钟 */
 	SD_SPI_ALL_APBxClock_FUN ( SD_SPI_ALL_CLK, ENABLE );
	
  /* 配置SPI的 CS引脚,普通IO即可 */
  GPIO_InitStructure.GPIO_Pin = SD_SPI_CS_PIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(SD_SPI_CS_PORT, &GPIO_InitStructure);
	
  /* 配置SPI的 SCK引脚*/
  GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
  GPIO_Init(SD_SPI_SCK_PORT, &GPIO_InitStructure);



  /* 配置SPI的 MOSI引脚*/
  GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
  GPIO_Init(SD_SPI_MOSI_PORT, &GPIO_InitStructure);

  /* 配置SPI的 MISO引脚*/
  GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(SD_SPI_MISO_PORT, &GPIO_InitStructure);
  /* 停止信号 FLASH: CS引脚高电平*/
  SPI_SD_CS_1;

 
	
}

//********************************************
void SD_2Byte_Write(uint16_t IOData)
{
	uint8_t BitCounter;
		
	for (BitCounter=0;BitCounter<16;BitCounter++)
	{
		SD_SPI_SCK_0;//CLK Low
		DelayUs(5);
		if(IOData&0x8000)//If the MSB of IOData is 1, then Do=1, else Do=0.
			SD_SPI_MOSI_1;//Do High
		else
			SD_SPI_MOSI_0;//Do Low
				
		SD_SPI_SCK_1;//CLK High
		DelayUs(5);
		
		IOData=IOData<<1;//Because the MSB is transmitted firstly, shift to next lower bit.
	}
}
//********************************************
void SD_Write(uint16_t IOData)
{
	uint8_t BitCounter;
	IOData=IOData<<8;
	
	for (BitCounter=0;BitCounter<8;BitCounter++)
	{
		SD_SPI_SCK_0;//CLK Low
		DelayUs(5);
		if(IOData&0x8000)//If the MSB of IOData is 1, then Do=1, else Do=0.
			SD_SPI_MOSI_1;//Do High
		else
			SD_SPI_MOSI_0;//Do Low
				
		SD_SPI_SCK_1;//CLK High
		DelayUs(5);
		
		IOData=IOData<<1;//Because the MSB is transmitted firstly, shift to next lower bit.
	}
}
 
//********************************************
uint16_t SD_2Byte_Read(void)
{
	uint16_t Buffer;
	uint8_t BitCounter;
	Buffer=0;
	
	for (BitCounter=0;BitCounter<16;BitCounter++)
	{
		SD_SPI_SCK_0;//CLK Low
		DelayUs(5);
		SD_SPI_SCK_1;//CLK High
		DelayUs(5);
		Buffer=Buffer<<1;//Because the MSB is transmitted firstly, shift to next lower bit.
		                 //Because the LSB will be damaged, we can not put this line under next line.
		if(READ_SD_SPI_MISO)  
			Buffer++;//If SPI_Din=1 then the LSB_of_Buffer=1.		
	}
	
	return Buffer;
}

//********************************************
uint16_t SD_Read(void)
{
	uint16_t Buffer;
	uint8_t BitCounter;
	Buffer=0xffff;
	
	for (BitCounter=0;BitCounter<8;BitCounter++)
	{
		SD_SPI_SCK_0;//CLK Low
		DelayUs(5);
		SD_SPI_SCK_1;//CLK High
		DelayUs(5);
		Buffer=Buffer<<1;//Because the MSB is transmitted firstly, shift to next lower bit.
		                 //Because the LSB will be damaged, we can not put this line under next line.
		if(READ_SD_SPI_MISO)  
			Buffer++;//If SPI_Din=1 then the LSB_of_Buffer=1.		
	}
	
	return Buffer;
}

四、部分代码说明

1、接线引脚定义

需要自定义引脚可在此处更改,STM32要自定义引脚的话也要注意引脚时钟使能的更改

1.2、STM32F103C8T6+TF卡模块

#define      SD_SPI_ALL_APBxClock_FUN       RCC_APB2PeriphClockCmd
#define      SD_SPI_ALL_CLK                 RCC_APB2Periph_GPIOB 


#define      SD_SPI_CS_APBxClock_FUN        RCC_APB2PeriphClockCmd
#define      SD_SPI_CS_CLK                  RCC_APB2Periph_GPIOB    
#define      SD_SPI_CS_PORT                 GPIOB
#define      SD_SPI_CS_PIN                  GPIO_Pin_6

//SCK引脚
#define      SD_SPI_SCK_APBxClock_FUN       RCC_APB2PeriphClockCmd
#define      SD_SPI_SCK_CLK                 RCC_APB2Periph_GPIOB   
#define      SD_SPI_SCK_PORT                GPIOB   
#define      SD_SPI_SCK_PIN                 GPIO_Pin_7
//MISO引脚
#define      SD_SPI_MISO_APBxClock_FUN      RCC_APB2PeriphClockCmd
#define      SD_SPI_MISO_CLK                RCC_APB2Periph_GPIOB    
#define      SD_SPI_MISO_PORT               GPIOB 
#define      SD_SPI_MISO_PIN                GPIO_Pin_8
//MOSI引脚
#define      SD_SPI_MOSI_APBxClock_FUN      RCC_APB2PeriphClockCmd
#define      SD_SPI_MOSI_CLK                RCC_APB2Periph_GPIOB    
#define      SD_SPI_MOSI_PORT               GPIOB 
#define      SD_SPI_MOSI_PIN                GPIO_Pin_9

五、基础知识学习与相关资料下载

1、STC89C52RC程序下载 直戳跳转

2、STM32F103C8T6程序下载
(1)串口下载 直戳跳转
(2)ST-LINK下载 直戳跳转
(3)J-LINK下载 直戳跳转
(4)DAP-LINK下载 直戳跳转

3、OLED0.96程序说明 直戳跳转

4、串口助手下载与使用
(1)安信可调试助手使用 直戳跳转
(2) sscom33串口调试助手使用 直戳跳转
(3)STC-ISP串口调试助手使用 直戳跳转

六、视频效果展示与程序资料获取

视频连接 直戳跳转
资料获取 ( 滑到最后添加个人号)

七、注意事项

1、VCC GND请勿接反,接反易烧
2、OLED显示异常时,排除接线接触不良

八、接线说明

STM32F103C8T6

  
/************************************************************************************
//  功能描述   : TF卡模块测试程序
//  测试条件   : STM32F103C8T6   晶振8M  系统时钟72M
接线
TF卡模块-------------------------------STM32F103C8T6
VCC------------------------------------3.3/5V
GND------------------------------------GND
CS-------------------------------------PB6 //
SCK------------------------------------PB7 //	
MISO-----------------------------------PB8 //	
MOSI-----------------------------------PB9 //	
*************************************************************************************/
Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐