本文主要是介绍鹏程万里------TI 28004开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
大丈夫能伸能屈。。。。。
1.gpio的功能定义在page875页
其实挺简单,就是前面加后面组成一个数字表明是第几个功能,比如如果要搞成canb_tx,那么就是0110换成10进制就是功能6,这个例子用在前一页的那些功能定义种。
2.In a typical application, the SPISTE pin serves as a chip-enable pin for a slave SPI device. This pin is
driven low by the master before transmitting data to the slave and is taken high after the transmission is
complete.这段话在page2052页,看起来似乎spi 会自动管控这个管教,只要定义成spi ste
3.下图是开发板的仿真器设置
先选basic的再选advance的
3.烧录程序:
烧录文件如下:
然后打开编译软件导入工程如下
点击load下载先,这是副cpu里的程序
然后
在右边
右键点击launchXXXXXXX
然后
选中c28xx右键connectXXXX
然后
然后点击load等待
选中那个out文件
然后等待下载完成即可
接下来说说28004的spi开发,我只做了flash读写相关,不过基本差不多
初始化spi gpio和controller
void initspib_gpio()
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO16 (SPISIMOA)
GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up on GPIO56 (SPICLKA)
//GpioCtrlRegs.GPBPUD.bit.GPIO58 = 0; // Enable pull-up on GPIO56 (SPICLKA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 3; // Asynch input GPIO12 (SPISIMOA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3; // Asynch input GPIO13 (SPISOMIA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Asynch input GPIO14 (SPICLKA)
//GpioCtrlRegs.GPBQSEL2.bit.GPIO58 = 3; // Asynch input GPIO14 (SPICLKA)
GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 2; // Configure GPIO12 as SPISIMOA
GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 2; // Configure GPIO13 as SPISOMIA
GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 2; // Configure GPIO14 as SPICLKA
GpioCtrlRegs.GPAGMUX2.bit.GPIO24 = 1;
GpioCtrlRegs.GPAGMUX2.bit.GPIO25 = 1;
GpioCtrlRegs.GPAGMUX2.bit.GPIO26 = 1;
//GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 6; // Configure GPIO14 as SPICLKA
//GpioCtrlRegs.GPBGMUX2.bit.GPIO58 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 0; // Configure GPIO15 as SPISTEB
GpioCtrlRegs.GPADIR.bit.GPIO27 = 1;
GpioDataRegs.GPASET.bit.GPIO27 = 1;
GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 3; // Asynch input GPIO15 (SPISTEB)
SpibRegs.SPICCR.bit.SPISWRESET = 0;
SpibRegs.SPICCR.bit.CLKPOLARITY = 1;
SpibRegs.SPICCR.bit.SPICHAR = (8-1);
SpibRegs.SPICCR.bit.SPILBK = 0;
SpibRegs.SPICTL.bit.MASTER_SLAVE = 1;
SpibRegs.SPICTL.bit.TALK = 1;
SpibRegs.SPICTL.bit.CLK_PHASE = 0;
SpibRegs.SPICTL.bit.SPIINTENA = 0;
SpibRegs.SPIBRR.bit.SPI_BIT_RATE = SPI_BRR;
SpibRegs.SPIPRI.bit.FREE = 1;
SpibRegs.SPICCR.bit.SPISWRESET = 1;
EDIS;
}
void SPI_flash_block_erase_64k(unsigned char *write_array)
{
SPI_flash_write_enable();
DELAY_US(1000);
SPI_writeArray1(write_array,4);
}
void SPI_writeArray1(unsigned char *write_array,uint16_t length)
{
int i;
uint16_t tempData = 0;
uint16_t tempData1 = 0;
uint16_t spi_rw_delay_cnt;
volatile struct SPI_REGS *p;
GpioDataRegs.GPACLEAR.bit.GPIO27 = 1;
for(i=0;i< length;i++)
{
//val = write_array[i];
tempData |= write_array[i];
tempData <<= 8;
p = &SpibRegs;
spi_rw_delay_cnt = 0;
while (1 == p->SPISTS.bit.BUFFULL_FLAG)
{
if(++spi_rw_delay_cnt > 1000)
{
spi_rw_delay_cnt = 0;
break;
}
}
//val1 = tempData;
p->SPITXBUF = tempData;
spi_rw_delay_cnt = 0;
while (0 == p->SPISTS.bit.INT_FLAG)
{
if(++spi_rw_delay_cnt > 1000)
{
spi_rw_delay_cnt = 0;
break;
}
}//SpiaRegs.SPISTS.bit.INT_FLAG ==1
tempData1 = p->SPIRXBUF;
DELAY_US(20);
}
GpioDataRegs.GPADAT.bit.GPIO27 = 1;
GpioDataRegs.GPASET.bit.GPIO27 = 1;
}
// only for spi flash read
void SPI_readArray(unsigned char *write_array,unsigned char *read_array,uint16_t length)
{
int i;
uint16_t tempData = 0;
uint16_t tempData1 = 0;
uint16_t spi_rw_delay_cnt;
volatile struct SPI_REGS *p;
GpioDataRegs.GPACLEAR.bit.GPIO27 = 1;
for(i=0;i< length;i++)
{
// val = write_array[i];
tempData |= write_array[i];
tempData <<= 8;
p = &SpibRegs;
spi_rw_delay_cnt = 0;
while (1 == p->SPISTS.bit.BUFFULL_FLAG)
{
if(++spi_rw_delay_cnt > 1000)
{
spi_rw_delay_cnt = 0;
break;
}
}
// val1 = tempData;
p->SPITXBUF = tempData;
spi_rw_delay_cnt = 0;
while (0 == p->SPISTS.bit.INT_FLAG)
{
if(++spi_rw_delay_cnt > 1000)
{
spi_rw_delay_cnt = 0;
break;
}
}//SpiaRegs.SPISTS.bit.INT_FLAG ==1
tempData1 = p->SPIRXBUF;
read_array[i] = (unsigned char)(tempData1 & 0xff);
}
GpioDataRegs.GPADAT.bit.GPIO27 = 1;
GpioDataRegs.GPASET.bit.GPIO27 = 1;
}
上面的读写都是针对单个byte的哦
在读取内存数据时发现一个很奇怪的现象
bin_len_byte = (long)(*((int*)0x9F001))*65536 + *((int*)0x9F002);
在这个情况下,如果9f001里存任何值,结果都只会又9f002里的值,但是如果
bLenCnt = (*((int*)0x9F001))*65536;
bLenCnt1 = (*(int*)0x9F002)&0x0000FFFF;
bin_len_byte = bLenCnt+bLenCnt1;
这个写法就正确,非常奇怪
这篇关于鹏程万里------TI 28004开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!