网站公告列表

  没有公告

加入收藏
设为首页
联系本站
您现在的位置: AnalogCN安诺电子 >> 文章 >> 技术交流 >> 文章正文
  BF533和触摸屏接口芯片TSC2200调试日志           ★★★ 【字体:
BF533和触摸屏接口芯片TSC2200调试日志
作者:yanhc519    文章来源:http://blog.csdn.net/yanhc519    点击数:    更新时间:2008-10-8    
下面是部分源代码:
//************************************************//
//** file: spi.c
//** target: ADSP-BF533
//** creat time: 2008-8-19
#include <ccblkfn.h>
#include <cdefBF533.h>
#include "sys_func.h"

//SPI interface funtion
void SPI_Init(void)
{
    *pSPI_BAUD = (unsigned short)(GetSCLK() / (2 * 5000000)); // 5MHz
    //SPI enable,master mode,CPHA=1(control by software),
    //16 bit,Start transfer with write of SPI_TDBR
    *pSPI_CTL = 0x5501;
    *pSPI_FLG = 0xFF20; // SPISEL5 enabled
}

//SPI send a word function
void SPI_send_data(unsigned short data)
{
*pSPI_TDBR = data;
while ((*pSPI_STAT & 0x0001) == 0) ;
Delay(1000);
}

//SPI receive a word function
unsigned short SPI_receive_data(void)
{
    SPI_send_data(0xFFFF);
    return (*pSPI_RDBR);
}

//SPI RDBR clear
void SPI_RDBR_Clr(void)
{
    unsigned char buf;

    while (*pSPI_STAT & 0x0020)
        buf = *pSPI_RDBR;
}


//*********************************************************//
#include <ccblkfn.h>
#include <cdefBF533.h>
#include <stdio.h>
#include "tsc2200_exp.h"
#include "sys_res.h"
#include "segled.h"
#include "sys_func.h"
#include "uart.h"
#include "spi.h"


//Read value of a register of TSC2200
unsigned short TSC2200_Read(unsigned short addr)
{
    unsigned short temp;  
    SPI_SEL_LOW;    //Clear SS low
    SPI_send_data(TSC_CMD_READ | addr);
    SPI_RDBR_Clr();        // Clear receiver buffer
    temp = SPI_receive_data();
    SPI_SEL_HIGH;   //Set SS high
    return temp;
}
//Write value to the register of TSC2200
void TSC2200_Write(unsigned short addr,unsigned short data)
{
    SPI_SEL_LOW;   //Clear SS low
    Delay(100);
    SPI_send_data(addr);
    SPI_send_data(data);
    Delay(100);
    SPI_SEL_HIGH; //Set SS high
}
//Check if the TSC2200 is exist
bool Detect_TSC2200(void)
{
    TSC2200_Write(TSC_CMD_RESET,RESET_RESET); //Reset the TSC2200
    Delay(100);
    return (TSC2200_Read(TSC_CMD_ADC) == 0x4000); //0x4000 is the default value of reg ADC
}
//Initial the TSC2200
void TSC2200_Init(void)
{
    TSC2200_Write(TSC_CMD_RESET,RESET_RESET); //Reset the TSC2200
    Delay(100);
    TSC2200_Write(TSC_CMD_ADC, 0xC4A2);Delay(100);//Stop ADC convertor
    TSC2200_Write(TSC_CMD_REF, 0x0017);Delay(100);
    TSC2200_Write(TSC_CMD_CFG, 0x000A);Delay(100);
    TSC2200_Write(TSC_CMD_ADC, 0x07FF);Delay(100); // Put TSC to Host and slowest mode
    TSC2200_Write(TSC_CMD_ADC, 0x84A2);Delay(100);    // Setup ADC,TSC control,Read XYZ,12 bit,8 bytes average
}
//Check if data is available
bool TSC2200DataAvailable(void)
{
    return ((TSC2200_Read(TSC_CMD_CFG) & CFG_DAVB) == 0x0000);
}
//Read the X Y coordinates
void TSC2200ReadXY(unsigned short *px,unsigned short *py)
{
    *px = TSC2200_Read(TSC_CMD_X);
    *py = TSC2200_Read(TSC_CMD_Y);
}

void Tsc2200_Exp(void)
{
    unsigned short temp = 0x0000,x,y; //Store the X,Y

    SPI_SELECT_TSC2200; // Set SPI select pin to TSC2200
   
    while(!Detect_TSC2200())
        printf("No TSC2200 exist!\n");
   
    printf("TSC2200 exist!\n");
   
    TSC2200_Init();
   
    while (1)
    {
        if (!(TSC2200_Read(TSC_CMD_CFG) & CFG_DAVB))
        {
            ledblk();
            TSC2200ReadXY(&x,&y);
            printf("X=%d;Y=%d;\n",x,y);
        }
    }
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    对比ADI两代TD-SCDMA射频IC得
    [结尾篇]ADSP-TS20XS系列DSP
    一种基于DDS的幅值可调信号发
    基于ADSP2181的CAN总线通讯设
    一种采用单片机控制AD9854为
    在vs2008下使用ffmpeg(5):
    在vs2008下使用ffmpeg(4):
    在vs2008下使用ffmpeg(3):
    ADI AD8275电平转换16位ADC驱
    Boot在ADSP-BF533上的移植
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    版权所有:AnalogCN安诺电子 湘ICP备06016315号