完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HII在1线通信中有一些问题。我的观点是:MPLAB X IDE V4.00 xC32 V1.44和声V2.3BICD3A定制板与PIC32 MZ2048 EC144和24MHz外部时钟C24001引脚2连接到ECH144引脚34(RB2)。DS2401引脚1和4连接到GND。我想读取DS24的序列号。01、在数据表(这里)的帮助下,我编写了这些函数:在程序开始时,我投下了iNITS.S.(),为了读取序列号,我写了WrdEyByTeTysn(0x0f),把读值放在一个char数组中,用RealthyByTysS~()来表示。我不知道我是否选择了错误的时间号。其他的设置,但是当我读取字符数组时,里面总是有0个。请告诉我,如果你对我的代码中的错误有什么想法的话?谢谢
以上来自于百度翻译 以下为原文 Hi I have some problems with an 1 wire communication. My spects : MPLAB X IDE V4.00 XC32 v1.44 HARMONY V2.3b ICD3 a custom board with PIC32MZ2048ECH144 and a 24Mhz external clock DS2401 pin 2 linked to the ECH144 pin 34 (RB2). DS2401 pin 1 and 4 linked to GND. I would like to read the serial number of a DS2401. With the help from the datasheet (here), I wrote these functions : bool Init_SSN(void) //initilisation Silicon Serial Number { int wait; PLIB_PORTS_PinDirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin in ouput PLIB_PORTS_ChangeNoticePullUpEnable(PORTS_ID_0, 34); //pull up enable PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin Higth PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin set Low wait = 19205; while(wait > 0) { Nop(); wait--; } //wait at least 480us => at 24Mhz (3+1+2)*42ns*1905=480us) PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin set hight PLIB_PORTS_PinDirectionInputSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin in input wait = 397; while(wait > 0) { Nop(); wait--; } //wait 60 to 240us => 6*42ns*397=100us return SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //return value send by the DS2401 } void write_bit_SSN(bool value) { int wait; PLIB_PORTS_PinDirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin output PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin set Low wait = 59; while(wait > 0) { Nop(); wait--; } //wait 1 to 15us => 6*42ns*59=15us if(value) //change the value if necessary { PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); } wait = 317; while(wait > 0) { Nop(); wait--; } //wait 45 to 105us => 80us } bool read_bit_SSN(void) { int wait; PLIB_PORTS_PinDirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin output PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin set Low PLIB_PORTS_PinDirectionInputSet(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //pin input wait = 8; while(wait > 0) { Nop(); wait--; } //wait 1us => 6*42ns*8=2us return SYS_PORTS_PinRead(PORTS_ID_0, PORT_CHANNEL_B,PORTS_BIT_POS_2); //return value send by the DS2401 } unsigned char read_byte_SSN(void) { unsigned char valueIn = 0; unsigned char coeff2 = 1; int i; for(i=0 ; i<8 ; i++) { valueIn = valueIn + read_bit_SSN() * coeff2; coeff2 = coeff2 * 2; } return valueIn; } void write_byte_SSN(unsigned char valueOut) { unsigned char masque = 0b00000001; int i; for(i=0;i<8;i++) { write_bit_SSN((valueOut & masque) >> i); masque = masque << 1; //*2 } } I cast Init_SSN() at the beginning of my program. And in order to read the serial numer, I cast write_byte_SSN(0x0F) and I put the reading values in a char array with read_byte_SSN(). I don't know if I chose the wrong time number or some other setting, but when I read the char array there are always 0 inside. Could you tell me please, if you have any idea about what is wrong in my code ? Thanks |
|
相关推荐
6个回答
|
|
你的读写字节可以被改写和改进,但我不确定它们是问题的根源。你能用范围检查线吗?
以上来自于百度翻译 以下为原文 Your read and write byte can be rewritten and improved, but I am not sure they're a source of problems. Can you check the lines with a Scope? |
|
|
|
感谢SmartScope的检查,我发现我的时间值不是我所期望的(似乎循环频率接近300兆赫不是24MHz)。所以我改变了所有的值来获得正确的时间范围。但是,另一个问题发生了,我为我的前两位获得了一个奇怪的电压信号。在我写0x0f时,我用示波器探头读取的信号:PictureI尝试了一些其他值,它总是用第一位和第二位。可能是因为我使用的上拉功能吗?当我编译我的程序时,编译器提示一个警告:…/SRC/APP.C:141:5:警告:“PLIPHPORTSURN CNPSPOLULLUPENT”是不支持的:选择的微控制器不实现这个特性。编辑:对不起,图片链接,我试图上传我的屏幕截图(SoCurLoL1.1.PNG 9KO),但我总是得到错误:你没有权限访问“http://www. McCys.com /论坛/上载.ASPX?”在这个服务器上.参考文献18.BB0FDD5815512701.1A76CB7
以上来自于百度翻译 以下为原文 Thanks for the answer I checked with SmartScope and I found my time value were not what I expected (seems the cycle frequency is near to 300 Mhz not 24MHz). So I changed all my values to obtain the right time ranges. But, another problem occurred, I obtain a strange voltage signal for my first two bits in writing. Here the signal read by my oscilloscope probe when I write 0x0F: Picture I tried with some other values, its always with first and second bits. Perhaps is due to the pull-up function I used ? When I compile my program the compiler prompt a warning : ../src/app.c:141:5: warning: 'PLIB_PORTS_CnPinsPullUpEnable' is unsupported: The microcontroller selected does not implement this feature. [enabled by default] edit: Sorry for the picture link, I tried to upload my screenshot (oscillo_1.png 39Ko), but I always obtain the error : You don't have permission to access "http://www.microchip.com/forums/upload.aspx?" on this server. Reference #18.bb0fdd58.1505122701.1a756cb7 |
|
|
|
我看不到你的图像,我不使用MCC:但是如果你没有在这些引脚上可用的内部弹出,你可能想要添加外部的(我在PIC16上用汇编中的一个线)。
以上来自于百度翻译 以下为原文 I can't see your image, and I don't use MCC: but if you have no internal pullups available on those pins, you may want to add external ones (I used One-Wire in Assembler on a PIC16) |
|
|
|
抱歉,因为一些晦涩的原因(访问被拒绝),我不能编辑我的帖子。谷歌驱动器链接不工作,我暂时上传我的图片免费(法语运营商):HTTP://DLFR.F/NGKAWVPWP
以上来自于百度翻译 以下为原文 Sorry for the late answer, for some obscur reason (access denied) I can't edit my post. Google drive link not working, I temporaly upload my picture by Free (french operator) : http://dl.free.fr/nGkAWVpwp |
|
|
|
好啊!所以,是的,当然可以。试试拉普拉斯
以上来自于百度翻译 以下为原文 Ok! so yes, definitely that could be. Try the pullups |
|
|
|
经过几次尝试:PrimthPosisPoopEndoRelabl(PosisSIDIO0,PosithChhanelyB,PosisS.BiTyPase2);PrBixPosisStEnEnoTiCuPull(PosisStIdIO0,34);SyssiPosisStEnEndoTrimeCuffPulkSuable(PurtsSyId0,34);最后,我与CNPUBITS.CNPUB2=1进行了一些改变;NGD,我得到这个。
以上来自于百度翻译 以下为原文 After several attemps with : PLIB_PORTS_PinOpenDrainEnable(PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_2); PLIB_PORTS_ChangeNoticePullUpEnable(PORTS_ID_0, 34); SYS_PORTS_ChangeNotificationPullUpEnable(PORTS_ID_0, 34); Finally, I had some changes with:CNPUBbits.CNPUB2 = 1; With the rest of my program unchanged, I obtain this. |
|
|
|
只有小组成员才能发言,加入小组>>
5162 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3172 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
731浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
629浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 05:34 , Processed in 1.249747 second(s), Total 86, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号