Microchip
直播中

h1654155275.5814

7年用户 216经验值
私信 关注
[问答]

怎么使用MICROSTICK II输出数据

嗨,我是新的PIC编程和MPLAB X。我试图描述ADC上的DSPIC33 EP32 GS202数字信号控制器。基本上,我需要在ADC中输入一些不同的波形,然后查看数据以了解ADC对我的应用程序的执行情况。在测试我的ADC代码之前,我需要确保我有一种方法来显示数据。我一直试图使用UART和Primff()使用CP2102 UART向USB桥接器发送数据给RealTerm。我使用硬件配置器生成了UART的代码,并检查了框以重定向Primff()到UART。我有CP2102连接到TX-RX和RX-TX到引脚上的DSPIC。我也有两个设备接地。我的代码如下:当我启动RealTerm并将波特率设置为9600(由我的程序指定的波特率)时,我得到的输出没有任何意义。它基本上是一群难以理解的人物。我显然错过了一些东西,但是尽管仔细检查了所有的东西,我还是不知道到底是什么。有没有办法调整我所做的事情来实现我的战略?如果不是,有没有更好的方法来使用MICROStiCK II输出数据?我只需要数据,使其成为一个文本文件,以便我可以绘制它,所以我没有什么要求的具体方法/应用我使用。谢谢!

以上来自于百度翻译


      以下为原文

    Hi,
           I'm new to PIC programming and MPLAB X. I'm trying to characterize the ADC on a dsPIC33EP32GS202 digital signal controller. Basically, I need to input some different waveforms into the ADC and then look at the data to see how well the ADC will perform for my application. Before I test my ADC code I need to ensure that I have a way to display the data. I've been trying to use the UART and printf() to send the data to RealTerm using a CP2102 UART to USB bridge. I generated code for the UART using the hardware configurator and checked the box to redirect printf() to the UART. I have the CP2102 connected to TX-RX and RX-TX to the pins on the dsPIC. I also have the two devices grounded together. My code is as follows:

/
void main(void)
{   
    //Initialize the I/O Pins
    PIN_MANAGER_Initialize();
   
    //Initialize the UART Interface
    UART1_Initialize();

    //Loop to test printf()
       while (1) {
           printf("Hello World:n");
            //UART1_Write(1);
            IO_RA0_SetHigh();
            for (i = 0; i == 100000000; i++){
                j++;
            }
        }
}


When I start RealTerm and set the Baud rate to 9600 (the baud rate specified by my program) I get output that doesn't make any sense. Its basically a bunch of unintelligible characters.

I'm obviously missing something, but despite double checking everything I can't really figure out what. Is there a way I can adjust what I'm doing to make my strategy work? If not, is there a better way to output the data using the microstick II?
I just need to data to make it into a text file so that I can plot it so I don't have any requirements about what specific method/application I use. Thanks!

回帖(7)

王璨

2019-1-21 16:09:53
你的时钟设置是什么?

以上来自于百度翻译


      以下为原文

    And what are your clock settings ?
举报

李艳婷

2019-1-21 16:20:11
谢谢你的回复!我使用的是由代码配置器生成的UART初始化函数:它看起来像UART时钟设置为30303025赫兹,这里我的波特率设置为57600,但我也尝试了其他波特率。我的内部振荡器设置为40兆赫,使我可以运行的ADC接近最大吞吐量。谢谢!

以上来自于百度翻译


      以下为原文

    Thanks for your response!
 
I'm using the UART initialize function generated by the code configurator:
 

void UART1_Initialize(void)
{
/**    
     Set the UART1 module to the options selected in the user interface.
     Make sure to set LAT bit corresponding to TxPin as high before UART initialization
*/
    // STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; URXINV disabled; UEN TX_RX;
    U1MODE = (0x8008 & ~(1<<15));  // disabling UARTEN bit   
    // UTXISEL0 TX_ONE_CHAR; UTXINV disabled; OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled;
    U1STA = 0x0;
    // BaudRate = 57600; Frequency = 30303025 Hz; BRG 131;
    U1BRG = 0x83;
    
    U1MODEbits.UARTEN = 1;  // enabling UARTEN bit
    U1STAbits.UTXEN = 1;
   
}

 
It looks like the UART clock is set to 30303025 Hz, here I have the baud rate set to 57600, but I've also tried other baud rates. I have the internal oscillator set to 40 MHz so that I can run the ADC close to the maximum throughput. Thanks!
举报

王璨

2019-1-21 16:29:36
你到底在期待什么????UART1IILIALALIZE()设置一些BRG值,假设时钟频率为30.1 MHz,时钟设置为40 MHZ。这不是一个关于软件的好概念。这是否来自MCC(运动的不同设置为“同一事物”)?或者从用户(看到我的签名)没有什么区别。我认为当BRG值从131变为173时,你的问题就会消失。

以上来自于百度翻译


      以下为原文

    What exactly are you expecting ???
UART1_Initialize() sets some BRG value assuming a clock frequency of 30.somehting MHz.
And the clock setup sets up 40 MHz.
 

is not a good concept regarding software. Whether this is from MCC (sporting different setting for "the same thing"?) or from the user (see my signature) makes little difference.

I assume that your problems will vanish when changing the BRG value from 131 to 173.
举报

李艳婷

2019-1-21 16:35:54
感谢您的响应和提醒,代码配置器生成什么不应该被认为是绝对正确的!U1BRG值无疑是一个问题。但是,即使我玩的价值,我不能让UART工作一致。例如,从先前的帖子中修正值不会给出工作结果。但是,如果我将主振荡器设置为4 MHz,并且设置BUG禁用的U1BRG= 0x18,则得到Prtff()以9600的波特率成功地工作。U1BRG是我理解的两倍,它应该是从数据表中计算出来的。我想弄清楚到底是怎么回事,但我还没到。我的振荡器初始化和UART初始化的代码都是为了验证振荡器的配置是否正确。有一件事我很难理解:主振荡器频率实际上是如何设置在寄存器上的?从参考手册中,我了解它是如何设置为XT的,它给出了一个4-10 MHz的范围,但我很难找出如何实际设置为4兆赫从那里(没有启用PLL)。即,位场或寄存器实际指定4 MHz对10 MHz或任何其他频率。4 MHz是我在代码配置器中选择的值。我真的很感激任何人提供的建议。谢谢!

以上来自于百度翻译


      以下为原文

    Thanks for your response and the reminder that what the code configurator generates should not be taken as definitely correct!
 
The U1BRG value is definitely an issue. But, even when I play around with the value I can't get the UART to work consistently. For example, correcting the value from the previous post does not give a working result. But, if I set the primary oscillator to 4 MHz, and set U1BRG = 0x18 with BRG disabled I get printf() to work successfully at a baud rate of 9600. U1BRG is double what I understand it should be in this case as calculated from the datasheet. I'm trying to figure out what's going on to cause this, but I haven't been able to as of yet. My code for oscillator initialization and UART initialization are below
 

// FOSCSEL
#pragma config FNOSC = PRI    // Oscillator Source Selection->Primary Oscillator (XT, HS, EC)
#pragma config IESO = ON    // Two-speed Oscillator Start-up Enable bit->Start up device with FRC, then switch to user-selected oscillator source

// FOSC
#pragma config POSCMD = XT    // Primary Oscillator Mode Select bits->XT Crystal Oscillator Mode
#pragma config OSCIOFNC = OFF    // OSC2 Pin Function bit->OSC2 is clock output
#pragma config IOL1WAY = ON    // Peripheral pin select configuration->Allow only one reconfiguration
#pragma config FCKSM = CSDCMD    // Clock Switching Mode bits->Both Clock switching and Fail-safe Clock Monitor are disabled
#pragma config PLLKEN = ON    // PLL Lock Enable Bit->Clock switch to PLL source will wait until the PLL lock signal is valid
 
void OSCILLATOR_Initialize(void)
{
    // CF no clock failure; NOSC PRI; CLKLOCK unlocked; OSWEN Switch is Complete;
    __builtin_write_OSCCONL((uint8_t) (0x200 & 0x00FF));
    // FRCDIV FRC/2; PLLPRE 5; DOZE 1:8; PLLPOST 1:8; DOZEN disabled; ROI disabled;
    CLKDIV = 0x31C3;
    // TUN Center frequency;
    OSCTUN = 0x0;
    // PLLDIV 148;
    PLLFBD = 0x94;
    // ENAPLL disabled; APSTSCLR 1:2; FRCSEL ASRCSEL determines input clock source; SELACLK Auxiliary Oscillators; ASRCSEL No clock input;
    ACLKCON = 0x2600;
    // LFSR 0;
    LFSR = 0x0;
}
 
void UART1_Initialize(void)
{
/**    
     Set the UART1 module to the options selected in the user interface.
     Make sure to set LAT bit corresponding to TxPin as high before UART initialization
*/
    // STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; URXINV disabled; UEN TX_RX;
    U1MODE = (0x8000 & ~(1<<15));  // disabling UARTEN bit   
    // UTXISEL0 TX_ONE_CHAR; UTXINV disabled; OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled;
    U1STA = 0x0;    
    // BaudRate = 9600; Frequency = 2000000 Hz; BRG 51;
    U1BRG = 0x18;
    
    U1MODEbits.UARTEN = 1;  // enabling UARTEN bit
    U1STAbits.UTXEN = 1;
   
}



 
I'm trying to verify that the oscillator is configured correctly. One thing I'm having trouble understanding: how is the primary oscillator frequency actually set in on of the registers? From the reference manual I understand how it is set to XT, which gives a range of 4-10 MHz, but I'm having trouble figuring out how is actually set to 4 MHz from there (without the PLL enabled). I.e., what bitfield or register actually specifies 4 MHz vs 10 MHz or any other frequency. 4 MHz is the value I selected in the code configurator. I would really appreciate any advice that anyone can offer. Thanks!
举报

更多回帖

发帖
×
20
完善资料,
赚取积分