想通过FIFO,把数组Uint16 dataA={123,123,123,123,123,123,123,123}发送到上位机,FIFO是一次发送8个数据,分别是dataA的8个元素,但用串口助手看到的是123的ASC码{;
如果考虑用itoa转成字符串,此时char* msg={1,2,3},就很棘手了,怎么用FIFO一次发送8个123啊?
Susan Yang:请问您现在使用的是哪款芯片?若是可以的话请给出相关代码,谢谢
想通过FIFO,把数组Uint16 dataA={123,123,123,123,123,123,123,123}发送到上位机,FIFO是一次发送8个数据,分别是dataA的8个元素,但用串口助手看到的是123的ASC码{;
如果考虑用itoa转成字符串,此时char* msg={1,2,3},就很棘手了,怎么用FIFO一次发送8个123啊?
user5866342:
回复 Susan Yang:
您好,我使用的是28335,部分代码如下,我现在并不知道该怎么写我想实现的这个功能
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define LED4 GpioDataRegs.GPADAT.bit.GPIO0#define LED3 GpioDataRegs.GPADAT.bit.GPIO1#define LED1 GpioDataRegs.GPADAT.bit.GPIO6#define LED2 GpioDataRegs.GPADAT.bit.GPIO7
interrupt void ISRTimer0(void);void configtestled(void);
void InitScibGpio();void Scib_Init(void);void Scib_Fifo_Init(void);interrupt void Scib_Tx_Isr(void);interrupt void Scib_Rx_Isr(void);void itoa(int num,char* str,int radix);
Uint16 i = 0;Uint16 k = 123;Uint16 dataB[8];Uint16 dataA[3] = {1,2,3};char* msg;
void main(void){// Step 1. Initialize System Control:// PLL, WatchDog, enable Peripheral Clocks// This example function is found in the DSP2833x_SysCtrl.c file. InitSysCtrl();
// Step 2. Initalize GPIO:// This example function is found in the DSP2833x_Gpio.c file and// illustrates how to set the GPIO to it's default state.// InitGpio(); // Skipped for this example InitXintf16Gpio(); //zq
// Step 3. Clear all interrupts and initialize PIE vector table:// Disable CPU interrupts DINT;
// Initialize the PIE control registers to their default state.// The default state is all PIE interrupts disabled and flags// are cleared.// This function is found in the DSP2833x_PieCtrl.c file. InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;
// PIE 向量表指针指向中断服务程(ISR)完成其初始化.// 即使在程序里不需要使用中断功能,也要对 PIE 向量表进行初始化.// 这样做是为了避免PIE引起的错误.// The shell ISR routines are found in DSP2833x_DefaultIsr.c.// This function is found in DSP2833x_PieVect.c. InitPieVectTable();
InitScibGpio();
// Interrupts that are used in this example are re-mapped to// ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &ISRTimer0; PieVectTable.SCITXINTB = &Scib_Tx_Isr; PieVectTable.SCIRXINTB = &Scib_Rx_Isr; //PieVectTable.XINT13 = &cpu_timer1_isr; //PieVectTable.TINT2 = &cpu_timer2_isr; EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be// found in DSP2833x_CpuTimers.c InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150, 500000); //ConfigCpuTimer(&CpuTimer1, 150, 1000000); //ConfigCpuTimer(&CpuTimer2, 150, 1000000); //StartCpuTimer0();
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13// which is connected to CPU-Timer 1, and CPU int 14, which is connected// to CPU-Timer 2: IER |= M_INT1; IER |= M_INT9; //IER |= M_INT13; //IER |= M_INT14; GpioDataRegs.GPBSET.bit.GPIO60=1;// Enable TINT0 in the PIE: Group 1 interrupt 7 PieCtrlRegs.PIECTRL.bit.ENPIE = 1; PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
PieCtrlRegs.PIEIER9.bit.INTx3 = 1; PieCtrlRegs.PIEIER9.bit.INTx4 = 1; // Enable global Interrupts and higher priority real-time debug events: EINT; // 总中断 INTM 使能 ERTM; // 使能总实时中断 DBGM
Scib_Init(); // Initalize SCIB Scib_Fifo_Init();
configtestled(); LED1=1; DELAY_US(10); LED2=1; DELAY_US(10); LED3=0; DELAY_US(10); LED4=0; DELAY_US(10); for(; ;);}
interrupt void ISRTimer0(void){ // Acknowledge this interrupt to receive more interrupts from group 1 PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断 CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志 CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据 LED1=~LED1; LED2=~LED2; LED3=~LED3; LED4=~LED4;
for(i=0; i<8; i++) { dataB[i]= k; }
ScibRegs.SCIFFTX.bit.TXFIFOXRESET = 1; // 复位发送 FIFO 指针 ScibRegs.SCIFFTX.bit.TXFFINTCLR = 1;
}
void Scib_Init(){ ScibRegs.SCICCR.all = 0x0007; ScibRegs.SCICTL1.all = 0x0003;
ScibRegs.SCICTL2.bit.TXINTENA = 1; ScibRegs.SCICTL2.bit.RXBKINTENA = 1;
ScibRegs.SCIHBAUD = 0x0001; // 9600 baud @LSPCLK = 37.5MHz ScibRegs.SCILBAUD = 0x00E7;
ScibRegs.SCICCR.bit.LOOPBKENA = 0; //Disable Loopback
}
void Scib_Fifo_Init(){ //ScibRegs.SCIFFTX.bit.SCIRST = 1; ScibRegs.SCIFFTX.bit.TXFIFOXRESET = 1; ScibRegs.SCIFFTX.bit.SCIFFENA = 1; ScibRegs.SCIFFTX.bit.TXFFST = 0; ScibRegs.SCIFFTX.bit.TXFFINT = 0; ScibRegs.SCIFFTX.bit.TXFFINTCLR = 0; ScibRegs.SCIFFTX.bit.TXFFIENA = 1; ScibRegs.SCIFFTX.bit.TXFFIL = 0;
ScibRegs.SCIFFRX.bit.RXFFOVF = 1; ScibRegs.SCIFFRX.bit.RXFFOVRCLR = 1; ScibRegs.SCIFFRX.bit.RXFIFORESET = 1; ScibRegs.SCIFFRX.bit.RXFFST = 0; ScibRegs.SCIFFRX.bit.RXFFINT = 0; ScibRegs.SCIFFRX.bit.RXFFINTCLR = 1; ScibRegs.SCIFFRX.bit.RXFFIENA = 1; ScibRegs.SCIFFRX.bit.RXFFIL = 3;
ScibRegs.SCIFFCT.all = 0x00; ScibRegs.SCICTL1.all = 0x0023; ScibRegs.SCICTL1.bit.SWRESET = 1;}
interrupt void Scib_Tx_Isr(void){ Uint16 i; for(i=0; i<8; i++) { itoa(dataB,msg,10); ScibRegs.SCITXBUF = msg[i]; } PieCtrlRegs.PIEACK.all |= PIEACK_GROUP9;
}
想通过FIFO,把数组Uint16 dataA={123,123,123,123,123,123,123,123}发送到上位机,FIFO是一次发送8个数据,分别是dataA的8个元素,但用串口助手看到的是123的ASC码{;
如果考虑用itoa转成字符串,此时char* msg={1,2,3},就很棘手了,怎么用FIFO一次发送8个123啊?
user5866342:
回复 Susan Yang:
请问,您有什么解决办法可以提出吗?