完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我的问题是,我想发送一个完整的数组由250个整数元素(这意味着它的大小是1000),通过UART1端口在我的PIC32 MX795F512H。下面的代码显示了我的UART的初始配置,sEndBuffd代码。我需要发送的不是很重要,有长整数。我知道如何用for循环发送它,它是有效的,但是当我实现sDeDigabuffFER发送所有数组(这实际上是我需要的)时,它也不起作用。与原始相比,我收到了不同的价值。
以上来自于百度翻译 以下为原文 Hello everybody, My problem is that i want to send a complete array made by 250 integer elements (that means its size is 1000), through the uart1 port in my PIC32MX795F512H. The code below shows the initial configuration of my uart, the sendbuffer code. What i need to send isn't that important, there are long integer numbers. I know how to send it with a for loop and it works, but when i implement the senddatabuffer to send all the array (that is actually what i need) it doesn´t work as well. i receive diferent values comparing with the original. /* * File: SPI2.c * Author: Santiago Villafuerte * * Created on 4 de abril de 2017, 09:45 AM */ // Configuration Bit settings // SYSCLK = 80 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV) // PBCLK = 80 MHz // Primary Osc w/PLL (XT+,HS+,EC+PLL) // WDT OFF // Other options don't care // #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1 #include #include #include #include //#include #include "definitions.h" #include "functions.h" /* * */ long int incomming_samples_CHN1[250]; const char CH1_DATA[1000]; UINT8 buf[1024]; void main(void) { //UART settings UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART1, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART1, GetPeripheralClock(), 460800); UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); int i; while(1){ memcpy((void*) (&(CH1_DATA[0])),(const void*) (&(incomming_samples_CHN1[0])), sizeof(incomming_samples_CHN1)); SendDataBuffer(CH1_DATA, sizeof(CH1_DATA)); // for(i=0; i<250; i++){ // sprintf(buf,"%in", incomming_samples_CHN1); // SendDataBuffer(buf, strlen(buf)); // // } } } // ***************************************************************************** // void UARTTxBuffer(char *buffer, UINT32 size) // ***************************************************************************** void SendDataBuffer(const char *buffer, UINT32 size) { while(size) { while(!UARTTransmitterIsReady(UART1)); UARTSendDataByte(UART1, *buffer); buffer++; size--; } while(!UARTTransmissionHasCompleted(UART1)); } |
|
相关推荐
6个回答
|
|
当您使用“for循环”时,您这样做:它将二进制中的整数转换为表示整数的ASCII字符,然后将ASCII发送到UART。将原始二进制文件发送为“sDeDigaDeffuffER”,并给您提供各种“有趣”字符:
以上来自于百度翻译 以下为原文 When you are using the 'for loop' you are doing this: sprintf(buf,"%in", incomming_samples_CHN1); which converts the integers in binary to ASCII characters representing the integer and then sending the ASCII out the UART. Sending out the raw binary as the 'SendDataBuffer' does with give you all kinds of 'interesting' characters: |
|
|
|
谢谢,伙计,我明白了。但是发送字符的时间太长了,这就是为什么我需要发送所有的数组,我需要一种方法来完成它。
以上来自于百度翻译 以下为原文 Thanks buddy, I got that. But it takes too long sending character by character, that's why i need to send all the array, and i need a way to accomplish it. I will apreciate any help. |
|
|
|
MMMM,发送单个元素或用一行代码行的整个数组是不可能的。
以上来自于百度翻译 以下为原文 Mmmm, it's unlikely that there will be any difference sending single elements or the whole array with a single line of code... |
|
|
|
460800是相当高的波特率。你使用什么类型的驱动程序,例如,Max?23是额定的120 KBs。尝试第一个低速和检查错误。
以上来自于百度翻译 以下为原文 460800 is quite high baud rate. What kind of driver do you you use, for example MAX232 is rated 120kbs. Try first low speed and check for errors. |
|
|
|
您可能需要某种协议来标记数组的开头,以便接收程序可以确定数组的起始位置。这是因为任何杂散字符都可以移位所有的字节。
以上来自于百度翻译 以下为原文 You may need some sort of protocol to mark the beginning of the array, so that the receiving program can figure out where is the beginning of the array. This is because any stray character may shift all further bytes. |
|
|
|
你把它送到哪里去了?它能处理那么多数据而不溢出吗?
以上来自于百度翻译 以下为原文 What are you sending it TO? Can it handle that much data coming in that fast without overflowing? |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
729浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
628浏览 0评论
526浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 15:43 , Processed in 1.166677 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号