cc2530下载程序

本文档详细介绍了如何使用外部MCU通过调试接口对CC2530微控制器进行编程,包括基本的命令定义、数据传输函数、读写内存操作以及配置和初始化流程。主要涉及调试接口的命令定义、XDATA区域的读写、SFR寄存器的访问、DMA通道的使用以及Flash编程等关键步骤。
摘要由CSDN通过智能技术生成
 

 外部mcu通过调试接口对CC2530进行编程,基本的功能函数如下:
<p>
//--cc2530 Debug commands---
#define CMD_CHIP_ERASE   0x10
#define CMD_WR_CONFIG    0x18
#define CMD_RD_CONFIG    0x20
#define CMD_READ_STATUS  0x30
#define CMD_RESUME       0x48
#define CMD_DEBUG_INSTR  0x50
#define CMD_BURST_WRITE  0x80
#define CMD_GET_CHIP_ID  0x68
//---------------------------

#define LOBYTE(w) ((unsigned char)(w))
#define HIBYTE(w) ((unsigned char)(((unsigned short)(w) >> 8) & 0xFF))

#define FCTL        0x6270
#define FADDRL      0x6271
#define FADDRH      0x6272
#define FWDATA      0x6273

#define DBGDATA     0x6260 //DMA register
#define X_DMAARM    0x70D6   //  DMA Channel Arm   
#define X_DMAREQ    0x70D7
#define X_DMA1CFGL  0x70D2   //  DMA Channel 1-4 Configuration Address Low Byte
#define X_DMA1CFGH  0x70D3   //  DMA Channel 1-4 Configuration Address High Byte  

// Buffers
#define ADDR_BUF0        0x0000 // 1K,存放来自调试接口的数据,长度为1K,0x0000--0x03FF
#define ADDR_DMA_DESC    0x0400 // 从0x0400地址开始存放16字节的数据
#define PROG_BLOCK_SIZE  0xFD

// DMA Channels
#define CH_DBG_TO_BUF0   0x02 //使用通道1
#define CH_BUF0_TO_FLASH 0x04 //使用通道2

//--mcu使用的下载接口引脚,可以根据具体的mcu修改----
sbit DcPin = PADBUF^5;
sbit DdPin = PADBUF^3;
sbit ResetPin = PADBUF^1;

sbit DcPinDir  = PADCON1^5;
sbit DdPinDir  = PADCON1^3;
sbit ResetPinDir = PADCON1^1;
//-------------------------------------------------------------------------

void Delayus(unsigned short us)
{
        while(us--)
        {
                _nop_();
                _nop_();
                _nop_();
                _nop_();
                _nop_();
                _nop_();
                _nop_();
                _nop_();
        }
}

/*********************************************************************************
 * Writes a byte on the debug interface. Sets the direction of port 0 at the end.
 * DdPin must be output when this function is called.
 * param:
   num---Byte to write
  dir---Direction of all pins on port 0 that is to be written at the end.
*********************************************************************************/
void cc2530_Write_Debug_Byte(unsigned char num, unsigned char dir)
{
 unsigned char i;
 
 for (i=0; i<8; i++)
 {  
  DdPin = (num&0x80) ? 1 : 0;     
  DcPin = 1;
  _nop_();
  _nop_();
  _nop_();
  _nop_();
  _nop_();   
  num <<= 1;       
  DcPin = 0; //在时钟的下降沿把数据输出               
 }
 
 DdPinDir = dir;  
}

/*****************************************************
 * Reads a byte from the debug interface.
 * Requires DdPin to be input when function is called.
 * return:
      Byte read
*****************************************************/
unsigned char cc2530_Read_Debug_Byte(void)
{
 unsigned char i,num;
   
 for (i = 0; i < 8; i++)
 {  
  DcPin = 1; // clock out data  
  num <<= 1;  
  num |= DdPin;  
  DcPin = 0;  
 }
   
 return num;
}

/********************************

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值