论坛上各位大神,有个问题想请教一下。我用研旭的TMS320C5502开发板进行按键点灯实验时遇到一个无法访问的问题,想请教一下:
通过DSP的外部数据线和地址线读取CPLD按键引脚的电平,再通过DSP的外部数据线和地址线来点亮CPLD的LED,程序运行下去,按下按键对应的灯没有反应,出现数据无法访问的问题。
:
程序源代码如下:
/**************************Copyright(c)************************************************
* * 南京研旭科技有限公司
* *
* *————————–文件信息————————————————–
* * 文 件 名:led_2.c
* * 创 建 人:南京研旭科技嵌入式部
* * 版 本:V1.0
* * 描 述;LED流水灯实验,本实验通过DSP的外部数据线和地址线读取CPLD按键引脚的电平,
再通过DSP的外部数据线和地址线来点亮CPLD的LED
***************************************************************************************/
#include <stdio.h>
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_irq.h>
#include <csl_gpt.h>
#include <math.h>
#include <csl_emif.h>
#include <csl_emifBhal.h>
#include <csl_gptdat.h>
#include <csl_gpthal.h>
#include <csl_uart.h>
#include <csl_uarthal.h>
EMIF_Config MyEmifConfig = {
EMIF_GBLCTL1_RMK( // EMIF Global Control Register 1
EMIF_GBLCTL1_NOHOLD_HOLD_ENABLED, // Hold enable
EMIF_GBLCTL1_EK1HZ_EK1EN, // High-Z control
EMIF_GBLCTL1_EK1EN_ENABLED // ECLKOUT1 Enable
),
EMIF_GBLCTL2_RMK( // EMIF Global Control Register 2
EMIF_GBLCTL2_EK2RATE_1XCLK, // ECLKOUT2 Rate
EMIF_GBLCTL2_EK2HZ_EK2EN, // EK2HZ = 0, ECLKOUT2 is driven with value specified by EKnEN during
EMIF_GBLCTL2_EK2EN_DISABLED // ECLKOUT2 Enable (enabled by default)
),EMIF_CE1CTL1_RMK( // CE1 Space Control Register 1
EMIF_CE1CTL1_TA_DEFAULT,
EMIF_CE1CTL1_READ_STROBE_DEFAULT,
EMIF_CE1CTL1_MTYPE_DEFAULT,
EMIF_CE1CTL1_WRITE_HOLD_MSB_DEFAULT,
EMIF_CE1CTL1_READ_HOLD_DEFAULT
),
EMIF_CE1CTL2_RMK( // CE1 Space Control Register 2
EMIF_CE1CTL2_WRITE_SETUP_DEFAULT,
EMIF_CE1CTL2_WRITE_STROBE_DEFAULT,
EMIF_CE1CTL2_WRITE_HOLD_DEFAULT,
EMIF_CE1CTL2_READ_SETUP_DEFAULT
),
EMIF_CE0CTL1_RMK( // CE0 Space Control Register 1
EMIF_CE0CTL1_TA_DEFAULT,
EMIF_CE0CTL1_READ_STROBE_DEFAULT,
EMIF_CE0CTL1_MTYPE_16BIT_ASYNC,
EMIF_CE0CTL1_WRITE_HOLD_MSB_DEFAULT,
EMIF_CE0CTL1_READ_HOLD_DEFAULT
),
EMIF_CE0CTL2_RMK( // CE0 Space Control Register 2
EMIF_CE0CTL2_WRITE_SETUP_DEFAULT,
EMIF_CE0CTL2_WRITE_STROBE_DEFAULT,
EMIF_CE0CTL2_WRITE_HOLD_DEFAULT,
EMIF_CE0CTL2_READ_SETUP_DEFAULT
),
EMIF_CE2CTL1_RMK( // CE2 Space Control Register 1
EMIF_CE2CTL1_TA_DEFAULT, // Not use for SDRAM (asynchronous memory types only)
EMIF_CE2CTL1_READ_STROBE_DEFAULT, // Read strobe width
EMIF_CE2CTL1_MTYPE_32BIT_SDRAM, // 32-bit-wide SDRAM
EMIF_CE2CTL1_WRITE_HOLD_DEFAULT, // Write hold width
EMIF_CE2CTL1_READ_HOLD_DEFAULT // Read hold width
),
EMIF_CE2CTL2_RMK( // CE2 Space Control Register 2
EMIF_CE2CTL2_WRITE_SETUP_DEFAULT, // Write setup width
EMIF_CE2CTL2_WRITE_STROBE_DEFAULT, // Write strobe width
EMIF_CE2CTL2_WRITE_HOLD_DEFAULT, // Write hold width
EMIF_CE2CTL2_READ_SETUP_DEFAULT // Read setup width
),
EMIF_CE3CTL1_RMK( // CE3 Space Control Register 1
EMIF_CE3CTL1_TA_DEFAULT, // Not use for SDRAM (asynchronous memory types only)
EMIF_CE3CTL1_READ_STROBE_DEFAULT, // Read strobe width
EMIF_CE2CTL1_MTYPE_32BIT_SDRAM, // 32-bit-wide SDRAM
EMIF_CE3CTL1_WRITE_HOLD_DEFAULT, // Write hold width
EMIF_CE3CTL1_READ_HOLD_DEFAULT // Read hold width
),
EMIF_CE3CTL2_RMK( // CE3 Space Control Register 2
EMIF_CE3CTL2_WRITE_SETUP_DEFAULT, // Write setup width
EMIF_CE3CTL2_WRITE_STROBE_DEFAULT, // Write strobe width
EMIF_CE3CTL2_WRITE_HOLD_DEFAULT, // Write hold width
EMIF_CE3CTL2_READ_SETUP_DEFAULT // Read setup width
),
EMIF_SDCTL1_RMK( // SDRAM Control Register 1
EMIF_SDCTL1_TRC_OF(6), // Specifies tRC value of the SDRAM in EMIF clock cycles.
EMIF_SDCTL1_SLFRFR_DISABLED // Auto-refresh mode
),
EMIF_SDCTL2_RMK( // SDRAM Control Register 2
0x11, // 4 banks,11 row address, 8 column address
EMIF_SDCTL2_RFEN_ENABLED, // Refresh enabled
EMIF_SDCTL2_INIT_INIT_SDRAM,
EMIF_SDCTL2_TRCD_OF(1), // Specifies tRCD value of the SDRAM in EMIF clock cycles
EMIF_SDCTL2_TRP_OF(1) // Specifies tRP value of the SDRAM in EMIF clock cycles
),
0x61B, // SDRAM Refresh Control Register 1
0x0300, // SDRAM Refresh Control Register 2
EMIF_SDEXT1_RMK( // SDRAM Extension Register 1
EMIF_SDEXT1_R2WDQM_1CYCLE,
EMIF_SDEXT1_RD2WR_3CYCLES,
EMIF_SDEXT1_RD2DEAC_1CYCLE,
EMIF_SDEXT1_RD2RD_1CYCLE,
EMIF_SDEXT1_THZP_OF(1), // tPROZ2=2
EMIF_SDEXT1_TWR_OF(0), //
EMIF_SDEXT1_TRRD_2CYCLES,
EMIF_SDEXT1_TRAS_OF(4),
EMIF_SDEXT1_TCL_2CYCLES
),
EMIF_SDEXT2_RMK( // SDRAM Extension Register 2
EMIF_SDEXT2_WR2RD_0CYCLES,
EMIF_SDEXT2_WR2DEAC_1CYCLE,
0,
EMIF_SDEXT2_R2WDQM_1CYCLE
),
EMIF_CE1SEC1_DEFAULT, // CE1 Secondary Control Register 1
EMIF_CE0SEC1_DEFAULT, // CE0 Secondary Control Register 1
EMIF_CE2SEC1_DEFAULT, // CE2 Secondary Control Register 1
EMIF_CE3SEC1_DEFAULT, // CE3 Secondary Control Register 1
EMIF_CESCR_DEFAULT // CE Size Control Register };
/* 通过定义宏来控制两个外围存储器映射的寄存器,从而实现对GPIO口的控制 */
#define GPIODIR (*(volatile ioport Uint16*)(0x3400))
#define GPIODATA (*(volatile ioport Uint16*)(0x3401))
#define LedReg (*(volatile Uint16*)(0x8008)) //发光二极管的地址
#define KeyReg (*(volatile Uint16*)(0x800C)) //按键地址
void main(void)
{
/* Initialize CSL library – This is REQUIRED !!! */
CSL_init();
/* PLL configuration structure used to set up PLL interface */
// 主频为300Mhz
PLL_setFreq(1, 0xF, 0, 1, 3, 3, 0);
CHIP_RSET(XBSR,0x0001);
EMIF_config(&MyEmifConfig); while(1)
{
if((KeyReg|0x0E)==0xE) LedReg=0xFE; //KEY0控制D9;按下KEY0;D9亮,D10、11、12灭
if((KeyReg|0x0D)==0xD) LedReg=0xFD; //KEY1控制D10;按下KEY1;D10亮其余灭 if((KeyReg|0x0B)==0xB) LedReg=0xFB; //KEY2控制D11;按下KEY2;D11亮其余灭
if((KeyReg|0x07)==0x7) LedReg=0xF7; //KEY3控制D12;按下KEY3;D12亮其余灭
}
}
Shine:
请问是运行到哪一句代码出现这个错误的?
其他程序有问题吗?
wei Wang34:
回复 Shine:
按键后LED没有任何反应,停止运行,发现程序停在whine(1){}内部的 if((KeyReg|0x0E)==0xE) LedReg=0xFE; 然后就报错说无法访问0x0800
Shine:
回复 wei Wang34:
请问按键后, 是通过什么机制去触发DSP EMIF去读keyreg的?
jia ji:
你好,看您也是用研旭5502板子的,能不能交流下,我用这块板子有些不明白的地方,谢谢。