9回答

1收藏

[分享] GD32F207驱动0.96寸OLED

GD32 GD32 5261 人阅读 | 9 人回复 | 2016-02-04

本帖最后由 党国特派员 于 2016-2-5 01:09 编辑

1、OLED介绍
0.96’ OLED 显示模块, 分辨率为 128*64,采用SSD1306 驱动 IC,该芯片内部集成 DCDC 升压,仅需 3.3V 供电,即可正常工作。实际上就是由一个SSD1306控制器和一个128X64的有机发光二极管点阵组成。OLD模块具有和12864LCD相同的分辨率,但其在单位面积上具有更多的像素点。该模块的驱动芯片是SSD1306Z,它是一款专门用于驱动OLED点阵屏的COMS芯片,其包含128个段和64个公共端。为了能够通过外部控制器向其写入用于显示的数字信息,其对外提供了8个数据引脚和5个控制脚,并向用户提供了4种总线接口。文中所采用的OLED模块可实现SPI和IIC两种总线接口模式,默认为SPI模式。在SPI模式下,仅有数据引脚的低2位和控制引脚的CS#,D/C#和RES#与单片机进行接口。为了能让OLED具有丰富的显示效果和灵活简便的操作方式,SSD1306Z向用户提供了丰富的操作指令集,另外还向用户提供了128x64位的GDDRAM(Graphic Display Data RAM)。由于所采用的OLED不带字库,因此无论是显示图形还是显示汉字,均需通过取模软件进行编码,然后按SPI协议,将对应的编码按照所确定的地址模式写入对应的CDDRAM中。编码原理如图1所示。图1给出了16*8编码格式的字符‘A’,由于8行为一页,因此其占据2页的高度,而宽度则占据8列。图1中的每一个方格代表一位,若要显示则置1,反之置0。向GDDRAM当中送数据时,先通过指令确定操作所需的地址模式及存储器的地址,然后先写‘A’的第2页的编码,再写其第3页的编码,即可完成编码的写入操作。图1所对应的编码为0x00,0x00,0xe0,0x9c,0xf0,0x80,0x00,0x00,0x08,0x0f,0x08,0x00,0x00,0x0b,0xoe,0x08,编码时高位在下,低位在上。同理,可得对任意汉字的编码。

               图1
2、模块的接口原理图

3、管脚说明:
     GND:电源地
     VCC:2.2V~5.5V
     D0:   CLK时钟    (高电平2.2V~5.5V)
     D1:   MOSI数据  (高电平2.2V~5.5V)
     RST: 复位          (高电平2.2V~5.5V)
     DC:  数据/命令   (高电平2.2V~5.5V)
在COLIBRI_GD32F207开发板上,我们使用SPI1来驱动,所以D0接PA5,D1接PA7,RST接PC3,DC接PC2,CS接地。
4、驱动代码:
oled.h
  1. /**
  2. ****************************************************************************************
  3. *
  4. * @file oled.h
  5. *
  6. * @brief Header file of lcd_oled.
  7. *
  8. * Copyright (C) TChip 2012-2015
  9. *
  10. * $Rev: 1.0 $
  11. *
  12. ****************************************************************************************
  13. */
  14. #ifndef        __OLED_H__
  15. #define        __OLED_H__

  16. /*
  17. * INCLUDE FILES
  18. ****************************************************************************************
  19. */
  20. #include "stdint.h"


  21. /*
  22. * MARCO VARIABLE DECLARATION
  23. ****************************************************************************************
  24. */
  25. #define        OLED_DC_PIN                GPIO_PIN_2
  26. #define        OLED_CS_PIN                GPIO_PIN_0
  27. #define        OLED_RST_PIN        GPIO_PIN_3
  28. #define        OLED_SCLK_PIN        GPIO_PIN_5
  29. #define        OLED_SDIN_PIN        GPIO_PIN_7

  30. #define OLED_DC         GPIOC
  31. #define OLED_RST        GPIOC
  32. #define OLED_CS         GPIOA
  33. #define OLED_SCLK       GPIOA
  34. #define OLED_SDIN       GPIOA

  35. #define ZEROPAD 1               // Pad with zero
  36. #define SIGN    2               // Unsigned/signed long
  37. #define PLUS    4               // Show plus
  38. #define SPACE   8               // Space if plus
  39. #define LEFT    16              // Left justified
  40. #define SPECIAL 32              // 0x
  41. #define LARGE   64              // Use 'ABCDEF' instead of 'abcdef'


  42. #define OLED_CMD  0        //写命令
  43. #define OLED_DATA 1        //写数据

  44. #define OLED_MODE 0
  45. #define SIZE 16
  46. #define XLevelL                0x00
  47. #define XLevelH                0x10
  48. #define Max_Column        128
  49. #define Max_Row                64
  50. #define        Brightness        0xFF
  51. #define X_WIDTH         128
  52. #define Y_WIDTH         64        

  53. //-----------------OLED端口定义----------------         
  54. //#define OLED_CS_Clr() gpio_write_pin(OLED_CS_PIN,GPIO_LOW)//CS
  55. //#define OLED_CS_Set() gpio_write_pin(OLED_CS_PIN,GPIO_HIGH)



  56. //#define OLED_DC_Clr() gpio_write_pin(OLED_RS_PIN,GPIO_LOW)//DC
  57. //#define OLED_DC_Set() gpio_write_pin(OLED_RS_PIN,GPIO_HIGH)

  58. //-----------------OLED端口定义----------------         
  59. #define OLED_CS_Clr() GPIO_ResetBits(OLED_CS,OLED_CS_PIN)//CS
  60. #define OLED_CS_Set() GPIO_SetBits(OLED_CS,OLED_CS_PIN)

  61. #define OLED_RST_Clr() GPIO_ResetBits(OLED_RST,OLED_RST_PIN)//RES
  62. #define OLED_RST_Set() GPIO_SetBits(OLED_RST,OLED_RST_PIN)

  63. #define OLED_DC_Clr() GPIO_ResetBits(OLED_DC,OLED_DC_PIN)//DC
  64. #define OLED_DC_Set() GPIO_SetBits(OLED_DC,OLED_DC_PIN)


  65. /*
  66. * EXTERN FUNCTION DECLARATION
  67. ****************************************************************************************
  68. */

  69. void OLED_WR_Byte(uint8_t dat,uint8_t cmd);            
  70. void OLED_Display_On(void);
  71. void OLED_Display_Off(void);                                                                                          
  72. void OLED_Init(void);
  73. void OLED_Clear(void);
  74. void OLED_DrawPoint(uint8_t x,uint8_t y,uint8_t t);
  75. void OLED_Fill(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint8_t dot);
  76. void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr);
  77. void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size);
  78. void OLED_ShowString(uint8_t x,uint8_t y, uint8_t *p);         
  79. void OLED_Set_Pos(unsigned char x, unsigned char y);
  80. void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no);
  81. void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]);
  82. #endif
  83. /// end
复制代码
oled.c
  1. /**
  2. ****************************************************************************************
  3. *
  4. * @file lcd_12864.c
  5. *
  6. * @brief lcd_12864 driver.
  7. *
  8. * Copyright (C) TChip 2014
  9. *
  10. * $Rev: 1.0 $
  11. *
  12. ****************************************************************************************
  13. */

  14. /**
  15. ****************************************************************************************
  16. * @addtogroup  SPI
  17. * @{
  18. ****************************************************************************************
  19. */

  20. /*
  21. * INCLUDE FILES
  22. ****************************************************************************************
  23. */
  24. #include "gd32f20x_gpio.h"              // Keil::Device:StdPeriph Drivers:GPIO
  25. #include "gd32f20x_spi.h"               // Keil::Device:StdPeriph Drivers:SPI

  26. #include "delay.h"
  27. #include "oled.h"
  28. #include "oledfont.h"

  29. /*
  30. * MARCO VARIABLE DECLARATION
  31. ****************************************************************************************
  32. */
  33. #define TRANSFER_SIZE               (1)                /*! Transfer size */
  34. #define TRANSFER_BAUDRATE           (1000000U)           /*! Transfer baudrate - 500k */
  35. #define MASTER_TRANSFER_TIMEOUT     (5000U)             /*! Transfer timeout of master - 5s */
  36. /*
  37. * LOCAL VARIABLE DECLARATION
  38. ****************************************************************************************
  39. */
  40. //check spi status
  41. volatile uint8_t        oled_rx_flag = 0;
  42. volatile uint8_t        oled_tx_flag = 0;

  43. //uint8_t i;
  44. uint8_t buffer[32];

  45. //Init the OLED
  46. //static uint8_t                 Init_buffer[] =
  47. //{
  48. //         0xAE ,//--turn off oled panel
  49. //         0x00 ,//---set low column address
  50. //         0x10 ,//---set high column address
  51. //         0x40 ,//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  52. //         0x81 ,//--set contrast control register
  53. //         0xCF , // Set SEG Output Current Brightness
  54. //         0xA1 ,//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  55. //         0xC8 ,//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  56. //         0xA6 ,//--set normal display
  57. //         0xA8 ,//--set multiplex ratio(1 to 64)
  58. //         0x3f ,//--1/64 duty
  59. //         0xD3 ,//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
  60. //         0x00 ,//-not offset
  61. //         0xd5 ,//--set display clock divide ratio/oscillator frequency
  62. //         0x80 ,//--set divide ratio, Set Clock as 100 Frames/Sec
  63. //         0xD9 ,//--set pre-charge period
  64. //         0xF1 ,//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  65. //         0xDA ,//--set com pins hardware configuration
  66. //         0x12 ,
  67. //         0xDB ,//--set vcomh
  68. //         0x40 ,//Set VCOM Deselect Level
  69. //         0x20 ,//-Set Page Addressing Mode (0x00/0x01/0x02)
  70. //         0x02 ,//
  71. //         0x8D ,//--set Charge Pump enable/disable
  72. //         0x14 ,//--set(0x10) disable
  73. //         0xA4 ,// Disable Entire Display On (0xa4/0xa5)
  74. //         0xA6 ,// Disable Inverse Display On (0xa6/a7)
  75. //         0xAF ,//--turn on oled panel
  76. //
  77. //         0xAF , /*display ON*/
  78. //};

  79. /*
  80. * GLOBAL VARIABLE DECLARATION
  81. ****************************************************************************************
  82. */


  83. #if (GD32_OLED)

  84. /**
  85. ****************************************************************************************
  86. * @brief SPI RX CALLBACK FUNCTION.
  87. * @description
  88. *
  89. ****************************************************************************************
  90. */
  91. void oled_read_done(void)
  92. {
  93.     oled_rx_flag = 0;
  94. }

  95. /**
  96. ****************************************************************************************
  97. * @brief SPI TX CALLBACK FUNCTION.
  98. * @description
  99. *
  100. ****************************************************************************************
  101. */
  102. void oled_write_done(void)
  103. {
  104.     oled_tx_flag = 0;
  105. }

  106. /**
  107. ****************************************************************************************
  108. * @brief Configure the SPI GPIO and set RS  、 RST GPIO output,Init them.
  109. * @description
  110. *
  111. ****************************************************************************************
  112. */
  113. void oled_io_config(void)
  114. {   
  115.         GPIO_InitPara GPIO_InitStructure;
  116.         /* Configure SPI_MASTER pins: SCK and MOSI */
  117.         GPIO_InitStructure.GPIO_Pin =  GPIO_PIN_5| GPIO_PIN_7;
  118.     GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
  119.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
  120.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  121.     //Init Gpio with a callback,it's necessary
  122.     //set the LCD_RS_PIN and LCD_RST_PIN an output
  123.         GPIO_InitStructure.GPIO_Pin =  OLED_DC_PIN| OLED_RST_PIN;
  124.     GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
  125.     GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP;
  126.     GPIO_Init(GPIOC, &GPIO_InitStructure);
  127.         
  128.         GPIO_ResetBits(GPIOC,OLED_DC_PIN);
  129.         GPIO_SetBits(GPIOC,OLED_RST_PIN);
  130. }


  131. void OLED_Set_Pos(unsigned char x, unsigned char y)
  132. {
  133.     OLED_WR_Byte(0xb0+y,OLED_CMD);
  134.     OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  135.     OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD);
  136. }
  137. //开启OLED显示
  138. void OLED_Display_On(void)
  139. {
  140.     OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  141.     OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  142.     OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  143. }
  144. //关闭OLED显示
  145. void OLED_Display_Off(void)
  146. {
  147.     OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  148.     OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  149.     OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  150. }
  151. //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
  152. void OLED_Clear(void)
  153. {
  154.     uint8_t i,n;
  155.     for(i=0; i<8; i++)
  156.     {
  157.         OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  158.         OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  159.         OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址
  160.         for(n=0; n<128; n++)
  161.           OLED_WR_Byte(0,OLED_DATA);
  162.     } //更新显示
  163. }

  164. void OLED_WR_Byte(uint8_t dat,uint8_t cmd)
  165. {
  166.     if(cmd)
  167.         OLED_DC_Set();
  168.     else
  169.         OLED_DC_Clr();
  170.     OLED_CS_Clr();
  171.     //spi_write(QN_SPI1, buffer, 1, oled_write_done);
  172.         SPI_I2S_SendData(SPI1,dat);
  173.     oled_write_done();
  174.     DelayUs(100);

  175.     OLED_CS_Set();
  176.     OLED_DC_Set();

  177. }

  178. //void OLED_WR_Byte(uint8_t dat,uint8_t cmd)
  179. //{
  180. //        //uint8_t i;
  181. //        uint8_t buffer[1];
  182. //        buffer[0] = dat;
  183. //        if(cmd)
  184. //          OLED_DC_Set();
  185. //        else
  186. //          OLED_DC_Clr();
  187. //        OLED_CS_Clr();
  188. //        spi_write(QN_SPI1, buffer, 1, lcd_write_done);
  189. //        delay(100);
  190. //
  191. //        OLED_CS_Set();
  192. //        OLED_DC_Set();
  193. //}


  194. void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr)
  195. {
  196.     unsigned char c=0,i=0;
  197.     c=chr-' ';//得到偏移后的值
  198.     if(x>Max_Column-1) {
  199.         x=0;
  200.         y=y+2;
  201.     }
  202.     if(SIZE ==16)
  203.     {
  204.         OLED_Set_Pos(x,y);
  205.         for(i=0; i<8; i++)
  206.             OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
  207.         OLED_Set_Pos(x,y+1);
  208.         for(i=0; i<8; i++)
  209.             OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
  210.     }
  211.     else {
  212.         OLED_Set_Pos(x,y+1);
  213.         for(i=0; i<6; i++)
  214.             OLED_WR_Byte(F6x8[c][i],OLED_DATA);

  215.     }
  216. }
  217. //m^n函数
  218. uint32_t oled_pow(uint8_t m,uint8_t n)
  219. {
  220.     uint32_t result=1;
  221.     while(n--)result*=m;
  222.     return result;
  223. }
  224. //显示2个数字
  225. //x,y :起点坐标
  226. //len :数字的位数
  227. //size:字体大小
  228. //mode:模式        0,填充模式;1,叠加模式
  229. //num:数值(0~4294967295);
  230. void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size)
  231. {
  232.     uint8_t t,temp;
  233.     uint8_t enshow=0;
  234.     for(t=0; t<len; t++)
  235.     {
  236.         temp=(num/oled_pow(10,len-t-1))%10;
  237.         if(enshow==0&&t<(len-1))
  238.         {
  239.             if(temp==0)
  240.             {
  241.                 OLED_ShowChar(x+(size/2)*t,y,' ');
  242.                 continue;
  243.             } else enshow=1;

  244.         }
  245.         OLED_ShowChar(x+(size/2)*t,y,temp+'0');
  246.     }
  247. }
  248. //显示一个字符号串
  249. void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr)
  250. {
  251.     unsigned char j=0;
  252.     while (chr[j]!='\0')
  253.     {   OLED_ShowChar(x,y,chr[j]);
  254.         x+=8;
  255.         if(x>120) {
  256.             x=0;
  257.             y+=2;
  258.         }
  259.         j++;
  260.     }
  261. }
  262. //显示汉字
  263. void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no)
  264. {
  265.     uint8_t t,adder=0;
  266.     OLED_Set_Pos(x,y);
  267.     for(t=0; t<16; t++)
  268.     {
  269.         OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
  270.         adder+=1;
  271.     }
  272.     OLED_Set_Pos(x,y+1);
  273.     for(t=0; t<16; t++)
  274.     {
  275.         OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
  276.         adder+=1;
  277.     }
  278. }
  279. /***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
  280. void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
  281. {
  282.     unsigned int j=0;
  283.     unsigned char x,y;

  284.     if(y1%8==0) y=y1/8;
  285.     else y=y1/8+1;
  286.     for(y=y0; y<y1; y++)
  287.     {
  288.         OLED_Set_Pos(x0,y);
  289.         for(x=x0; x<x1; x++)
  290.         {
  291.             OLED_WR_Byte(BMP[j++],OLED_DATA);
  292.         }
  293.     }
  294. }


  295. //初始化SSD1306
  296. void OLED_Init(void)
  297. {
  298.     oled_io_config();

  299.     OLED_RST_Set();
  300.     DelayMs(10);
  301.     OLED_RST_Clr();
  302.     DelayMs(10);
  303.     OLED_RST_Set();


  304.     OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  305.     OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  306.     OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  307.     OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  308.     OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
  309.     OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
  310.     OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  311.     OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  312.     OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
  313.     OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  314.     OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
  315.     OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
  316.     OLED_WR_Byte(0x00,OLED_CMD);//-not offset
  317.     OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
  318.     OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  319.     OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
  320.     OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  321.     OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
  322.     OLED_WR_Byte(0x12,OLED_CMD);
  323.     OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
  324.     OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
  325.     OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  326.     OLED_WR_Byte(0x02,OLED_CMD);//
  327.     OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
  328.     OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
  329.     OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
  330.     OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
  331.     OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel

  332.     OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
  333.     OLED_Clear();
  334.     OLED_Set_Pos(0,0);
  335. }

  336. #endif
  337. ///end


复制代码
主程序:main.c
  1. #include <stdio.h>
  2. #include "gd32f20x.h"                   // Device header
  3. #include "cmsis_os.h"                   // ARM::CMSIS:RTOS:Keil RTX

  4. #include "delay.h"
  5. #include "oled.h"

  6. void RCC_config(void);
  7. void SPI_config(void);

  8. int main()
  9. {   
  10.         osKernelInitialize();
  11.         
  12.         RCC_config();

  13.         SPI_config();

  14.         
  15.         osKernelStart();
  16.         while(1)
  17.         {
  18.                 OLED_ShowString(32,0,(uint8_t*)"WELCOME");
  19.                 OLED_ShowString(0,2,"Hello EEBoard!");
  20.                 OLED_ShowString(0,4,"COLIBRI_GD32F207");
  21.                 osDelay(1000);
  22.         }
  23. }

  24. void RCC_config(void)
  25. {
  26.     RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA|RCC_APB2PERIPH_GPIOD|RCC_APB2PERIPH_GPIOC,ENABLE);

  27.         RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_SPI1,ENABLE);
  28.         RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_ADC1,ENABLE);
  29.         
  30.         RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_USART2,ENABLE);
  31.         RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER6,ENABLE);
  32.         RCC_ADCCLKConfig(RCC_ADCCLK_APB2_DIV6);
  33. }



  34. void SPI_config(void)
  35. {
  36.         SPI_InitPara spi_stru;
  37.         
  38.         spi_stru.SPI_FirstBit = SPI_FIRSTBIT_MSB;
  39.         spi_stru.SPI_FrameFormat =  SPI_FRAMEFORMAT_8BIT;
  40.         spi_stru.SPI_Mode = SPI_MODE_MASTER;
  41.         spi_stru.SPI_PSC = SPI_PSC_64;
  42.         spi_stru.SPI_SCKPH = SPI_SCKPH_1EDGE;
  43.         spi_stru.SPI_SCKPL = SPI_SCKPL_LOW;
  44.         spi_stru.SPI_SWNSSEN = SPI_SWNSS_SOFT;
  45.         spi_stru.SPI_TransType = SPI_TRANSTYPE_BDMTX;
  46.         spi_stru.SPI_CRCPOL = 7;
  47.         
  48.         SPI_Init(SPI1,&spi_stru);
  49.         SPI_CRC_Enable(SPI1,DISABLE);
  50.         SPI_Enable(SPI1,ENABLE);
  51. }

复制代码
实验结果:


喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
分享到:
回复

使用道具 举报

回答|共 9 个

倒序浏览

沙发

小菜儿

发表于 2016-2-4 09:28:20 | 只看该作者

快过年了,还不忘学习,赞!
板凳

党国特派员

发表于 2016-2-4 10:02:29 | 只看该作者

小菜儿 发表于 2016-2-4 09:28
快过年了,还不忘学习,赞!

过年这几天轻闲,把这段时间的成果发贴子总结一下!
喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
地板

糖悦之果飞

发表于 2016-2-16 13:59:34 | 只看该作者

亲,可以将内容一并发到经验频道,很有机会获得每月之星的呢http://jingyan.eeboard.com/
5#

党国特派员

发表于 2016-2-16 14:47:20 | 只看该作者

糖悦之果飞 发表于 2016-2-16 13:59
亲,可以将内容一并发到经验频道,很有机会获得每月之星的呢http://jingyan.eeboard.com/ ...

晚上我整理下,然后发上去。
喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
6#

糖悦之果飞

发表于 2016-2-17 09:41:31 | 只看该作者

党国特派员 发表于 2016-2-16 14:47
晚上我整理下,然后发上去。

好的呢,看到啦!
7#

认真铭记

发表于 2016-2-19 20:06:15 | 只看该作者

cmsis_os.h 如何添加 我这里没有啊
8#

党国特派员

发表于 2016-2-20 21:38:44 | 只看该作者

认真铭记 发表于 2016-2-19 20:06
cmsis_os.h 如何添加 我这里没有啊

建立项目 的时候选择 RTOS(API)
喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
9#

党国特派员

发表于 2016-2-20 21:56:31 | 只看该作者

认真铭记 发表于 2016-2-19 20:06
cmsis_os.h 如何添加 我这里没有啊

如果不使用操作系统,你可以不用这个头文件。

喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
10#

认真铭记

发表于 2016-2-21 00:05:01 | 只看该作者

党国特派员 发表于 2016-2-20 21:56
如果不使用操作系统,你可以不用这个头文件。

知道了 多谢多谢!!!!!!!!!!!!!
您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条