//***************************************************************
整个调用的流程:
1) 实现r_dat_bat()等函数, spi的读写操作函数;
已按照要求实现r_dat_bat()函数及SPI驱动函数(软件模拟)
现在遇到的问题是利用函数
ASCII_GetData(*text, ASCII_8X16, FontBuf);
获取到的值与目标值不对应,实在没搞明白哪出错了
#include "font_library.h"
#include <stdio.h>
#include "at32f413_gpio.h"
void FL_Init(void)
{
gpio_init_type boo;
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
boo.gpio_drive_strength=GPIO_DRIVE_STRENGTH_STRONGER;
boo.gpio_mode=GPIO_MODE_OUTPUT;
boo.gpio_out_type=GPIO_OUTPUT_PUSH_PULL;
boo.gpio_pins=GPIO_PINS_5|GPIO_PINS_7|GPIO_PINS_4;
boo.gpio_pull=GPIO_PULL_UP;
gpio_init(GPIOA,&boo);
boo.gpio_pins=GPIO_PINS_0|GPIO_PINS_14;
gpio_init(GPIOB,&boo);
boo.gpio_mode=GPIO_MODE_INPUT;
boo.gpio_pins=GPIO_PINS_6;
gpio_init(GPIOA,&boo);
FL_SCK_H();
FL_NSS_H();
FL_MOSI_H();
}
void FL_Deinit(void)
{
#ifdef FL_SPI_SOFT
FL_MOSI_L();
FL_SCK_L();
FL_NSS_H();
#else
HAL_SPI_DeInit(&hspi4);
FL_NSS_H();
#endif
}
uint8_t FL_SPI_RW(uint8_t data)
{
#ifdef FL_SPI_SOFT
uint8_t bit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++) // 输出8位
{
if(data&0x80){FL_MOSI_H();}
else {FL_MOSI_L();}
data=(data<<1);
FL_SCK_L();
data|=FL_MISO_IN();
FL_SCK_H();
}
return data;
#else
uint8_t Rxdata;
HAL_SPI_TransmitReceive(&hspi4,&data,&Rxdata,1, 1000);
return Rxdata; //返回收到的数据
#endif
}
void Send_Byte(unsigned char out)
{
unsigned char i=0;
for(i=0;i<8;i++)
{
FL_SCK_L(); //字库芯片时钟置低
if(((out<<i)&0x80)==0)
FL_MOSI_L();
else
FL_MOSI_H();
FL_SCK_H();
}
}
unsigned char Get_Byte(void)
{
unsigned char i;
unsigned char read_dat;
FL_SCK_H();
for(i=0;i<8;i++)
{
FL_SCK_L();
read_dat=read_dat<<1;
if(FL_MISO_IN())
read_dat|=0x01;
else
read_dat&=0xfe;
FL_SCK_H();
}
return(read_dat);
}
unsigned char r_dat_bat(unsigned long address,unsigned long byte_long,unsigned char *p_arr)
{
unsigned long i;
unsigned char addrHigh;
unsigned char addrMid;
unsigned char addrLow;
addrHigh=address>>16;
addrMid=address>>8;
addrLow=(unsigned char)address;
FL_NSS_L(); //片选选中字库芯片
Send_Byte(0x03); //普通读取首先送0X03,然后发送地址高八位addrHigh,中八位addrMid,低八位addrLow。
Send_Byte(addrHigh);
Send_Byte(addrMid);
Send_Byte(addrLow);
for(i=0;i<byte_long;i++)
*(p_arr+i)=Get_Byte();
FL_NSS_H();
// FL_NSS_L(); //片选选中字库芯片
// FL_SPI_RW(0x03); //普通读取首先送0X03,然后发送地址高八位addrHigh,中八位addrMid,低八位addrLow。
// FL_SPI_RW(addrHigh);
// FL_SPI_RW(addrMid);
// FL_SPI_RW(addrLow);
// for(i=0;i<byte_long;i++)
// *(p_arr+i)=FL_SPI_RW(0xFF);
// FL_NSS_H();
return 0;
}
static uint8_t FontBuf[128]={0};
uint8_t *text="A";
int main(void)
{
system_clock_config();
at32_board_init();
// button_exint_init();
FL_Init();
while(1)
{
at32_led_toggle(LED2);
delay_ms(g_speed * DELAY);
ASCII_GetData(*text, ASCII_8X16, FontBuf);
// at32_led_toggle(LED3);
// delay_ms(g_speed * DELAY);
// at32_led_toggle(LED4);
// delay_ms(g_speed * DELAY);
}
}