pic 18F46k80 EUART

时间:2016-03-19 11:53:47

标签: uart mplab pic18

我正试图通过EUSART将数据传输到计算机。我已经设置了所有配置位,但串行通信仍然不能正常工作。我的Pc中只收到错误的数据。这是我设置uart的代码(我使用的是mplab编译器XC8):

int initialize(Iotfclient *client, char *orgId, char *deviceType, char *deviceId, char *authmethod, char *authtoken);
/**
* Function used to initialize the IBM Watson IoT client using the config file which is generated when you register your device
* @param client - Reference to the Iotfclient
* @param configFilePath - File path to the configuration file 
*
* @return int return code
* error codes
* CONFIG_FILE_ERROR -3 - Config file not present or not in right format
*/

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

在加载要发送的下一个字节之前,发送缓冲区寄存器必须为空。从数据手册:"一旦TXREGx寄存器将数据传输到TSR寄存器(发生在一个TCY中),TXREGx寄存器为空,TXxIF标志位置1。"

看来对象是反复发送' L'在9600波特,延迟允许主机处理接收的数据。所以改为最后几行:

TXSTA1bits.TXEN = 1;
while(1){
  while (PIR1bits.TX1IF == 0);
  TXREG = 76;
  __delay_ms(100); 
}

答案 1 :(得分:0)

这是我的代码配置位,我的外部振荡器是100%4 MHz,我没有示波器:(

from flask_assets import Bundle, Environment
import os

css = Bundle(
    "libs/bootstrap/dist/css/spacelab/bootstrap.css",
    "bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css",
    "css/style.css",
    "css/home.css",
    filters="cssmin",
    output="public/css/common.css"
)

js = Bundle(
    "libs/jQuery/dist/jquery.js",
    "libs/bootstrap/dist/js/bootstrap.js",
    "bower_components/moment/moment.js",
    "bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js",
    "js/plugins.js",
    filters='jsmin',
    output="public/js/common.js"
)


assets = Environment()

assets.register("js_all", js)
assets.register("css_all", css)