打印
[STM32F1]

【小道场】SPI中断 读出字库芯片 字模 问题

[复制链接]
1260|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
仙人球W|  楼主 | 2014-11-27 10:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 仙人球W 于 2014-11-27 10:19 编辑

硬件:1,字库芯片GT21L16S2Y
            (07040010)GT21L16S2Y用户手册V36.pdf (430.96 KB)
          2,板子 STM32F103C8
          3,SPI通讯

1,仿真打断点片选引脚电位正常
2,仿真进入中断,打断点LCDDriver.SPIDataCounter计数到32
问题:LCDDriver.FontData[]数组没有数据

先贴主要代码:
#define  FontChipSel 12
#define FontChipSel_EN()      GPIOB->BRR=(1<<FontChipSel) //拉低 字库芯片片选脚
#define FontChipSel_Dis()    GPIOB->BSRR=(1<<FontChipSel) //置高 字库芯片片选脚

void SPI2_Initial(void)
{
        SPI_InitTypeDef   SPI_InitStruct;
        GPIO_InitTypeDef GPIO_InitStructure;        

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE );


          SPI_I2S_DeInit(SPI2);
          SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
          SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
          SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
          SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
          SPI_InitStruct.SPI_CPHA = SPI_CPHA_2Edge;
          SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;
          SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
          SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
          SPI_InitStruct.SPI_CRCPolynomial = 7;
          SPI_Init(SPI2,&SPI_InitStruct);
          SPI_Cmd(SPI2,ENABLE);

        GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_12; //SPI片选
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //OUT         
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        //Configure SPI2 pins: SCK, MISO and MOSI
       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
       GPIO_Init(GPIOB, &GPIO_InitStructure);
}


void NVIC_Configuration(void)
{
       NVIC_InitTypeDef NVIC_InitStructure;
   
        /* Configure the NVIC Preemption Priority Bits */  
       NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
        
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
        NVIC_Init(&NVIC_InitStructure);        
}


void SPI2_ExecuteRequest(void)
{
           SPI2->CR2|=SPI_INT_RXENIE;  //使能数据接收完成中断   
           while((SPI2->SR&0x02)==0);        //发送缓冲非空就一直等待
           SPI2->DR=UsualRead;
}

/***************************************************
*MSB 表示汉字内码GBCode的高8bits
*LSB 表示汉字内码GBCode的低8bits
*Addr[0]字库芯片最高地址字节
*Addr[1]字库芯片其次地址字节
*Addr[2]字库芯片低地址字节
****************************************************/
FLAG  Get_GB15x16_Addr(BYTE MSB,BYTE LSB,BYTE *Addr)
{
        u32 Address=0;
        FLAG ReVal=TRUE;
       
        if(MSB == 0xA9&& LSB >=0xA1)
                    Address =(282+ (LSB-0xA1))*32+BaseAdd15x16;
        else if(MSB >=0xA1 && MSB <= 0xA3&& LSB >=0xA1)
                    Address =((MSB-0xA1) * 94 + (LSB-0xA1))*32+ BaseAdd15x16;
        else if(MSB >=0xB0 && MSB <= 0xF7 && LSB >=0xA1)
                    Address = ((MSB-0xB0) * 94 + (LSB-0xA1)+ 846)*32+ BaseAdd15x16;
        else
                ReVal=FALSE;
           Addr[0]=(BYTE)((Address>>16)&0xff);
           Addr[1]=(BYTE)((Address>>8)&0xff);
           Addr[2]=(BYTE)(Address&0xff);  
          return(ReVal);
}       

void Chinese_character(void)
{
        BYTE CMSB,CLSB;

        strcpy(tBuffer,"中文汉字编译测试");     // 编译后,拷贝到tBuffer的是汉字内码

        CMSB = tBuffer[2];
        CLSB = tBuffer[3];
        
        Get_GB15x16_Addr(CMSB,CLSB,LCDDriver.FontChipAddr);        
}

void SPI2_IRQHandler(void)
{
         u8 Temp;
        
         Temp= SPI2->DR;

         if(StartReceFont) //数据接收中断
            {
                     LCDDriver.FontData[LCDDriver.SPIDataCounter++]= Temp;
                     //if(LCDDriver.SPIDataCounter>=LCDDriver.FontDataNum)        //占时是汉字 32个字节
                     if(LCDDriver.SPIDataCounter>=32)        //占时是汉字 32个字节
                     {
                              LCDDriver.SPIDataCounter=0;
                             EndFontRece=1; //一个点阵字符或汉字接收完成
                             StartReceFont=0;
                             SPI2->CR2&=~SPI_INT_RXENIE;
                         FontChipSel_Dis(); //禁止字库片选
                     }
                     else
                          SPI2->DR=0xff; //发送一个Dummy字节数据以便产生Clock
            }
         else if(SPIStartSent)
           {
                    if(LCDDriver.SPIDataCounter>=3) //三个地址一个Dummy
                     {
                              SPI2->DR=0xff; //发送一个Dummy字节数据以便产生Clock
                              StartReceFont=1;
                              SPIStartSent=0;
                              LCDDriver.SPIDataCounter=0;
                     }
                   else
                             SPI2->DR=LCDDriver.FontChipAddr[LCDDriver.SPIDataCounter++];
           }
}

//=========================
// 函数名:main
//描述  :主函数
//输入  :无
//输出  :无
//=========================
int main(void)
{         
        //配置串口1为:9600 8-N-1
        USART1_Config();
        //配置SPI2
        SPI2_Initial();
        
        NVIC_Configuration();

        Chinese_character();

        printf("\r\n 这是一个2M串行flash(W25Q16)实验 \r\n");

        FontChipSel_EN();
          SPIStartSent=1;
          LCDDriver.SPIDataCounter=0;
         
        SPI2_ExecuteRequest();
        
        while(1)
        {
                ;
        }
}

沙发
仙人球W|  楼主 | 2014-11-27 14:58 | 只看该作者
顶一个 大神们

使用特权

评论回复
板凳
仙人球W|  楼主 | 2014-11-27 17:16 | 只看该作者
没人用SPI的中断方式么?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

38

主题

720

帖子

5

粉丝