完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
因此,对于我(作为asm用户和xc8初学者)来说,发现MCCI2c代码并不是一件容易的工作,因为它不太明显,比如:Start()、Write()、Stop()。而且我没有在网上找到示例。首先我检查了写函数,它没有工作。我发现固件在line:.(status==I2C_MESSAGE_PENDING);(它等待中断并在那里改变状态)进入无限循环。固件成功地进入其中,并选择正确的CASSESSMAStiORIDLE & gt;固件在它们之间循环。我检查了固件循环的LED。如果固件在某处- LED是打开的。然后我去示波器并没有找到任何CLK或数据信号。隐马尔可夫模型。。。所以我返回了II2CIILIALIALIZE();我使用了主模式,400 KHz的速度和7位的地址。2个上拉电阻2KOHM到VDD 5V。MCU -PIC16F1454与PoCc0和PoTC1引脚= CLK和数据。48兆赫FRQ(16X3PLL)。使用I2C,我使用正确的UB-UART CDC连接。我需要帮助找到错误的地方。编辑:我发现了2个错误。1)错误理解MCC波特率发生器的频率值。见下面的帖子。2)我的错误-我没有在PORTC上把模拟转换为数字输入,因为我认为PIC16F1454没有ADC,所以引脚总是数字的。
以上来自于百度翻译 以下为原文 So, for me (as asm user and xc8 beginner) discovering MCC i2c code wasn’t an easy job because it wasn’t too obvious like: Start(); Write(); Stop(). And I didn’t find examples on the internet. Since a week I made functions for writing and reading ext EEPROM 24AA256. First I checked the Write function and it didnt work. I found the firmware goes to infinite loop at line: while(status == I2C_MESSAGE_PENDING); (which waiting for interrupts and change the status there). After that I checked the function calling by i2c interrupts: I2C_ISR();. Firmware successfully enter in it and choose the right cases S_MASTER_IDLE -> S_MASTER_SEND_ADDR -> S_MASTER_SEND_DATA. And the firmware loops here between them. I checked where the firmware loops by LED. If firmware was somewhere - LED is on. Then I took oscilloscope and didnt find any CLK or DATA signal. Hmm... So I returned to I2C_Initialize();. I use Master mode, 400kHz speed with 7bit address. 2 pull-up resistors 2kOhm to Vdd 5V. MCU - PIC16F1454 with PORTC0 and PORTC1 pins = CLK and DATA. 48MHz freq (16x3PLL). And with I2C I use correctly working USB-UART CDC connection. I need help to find where I mistake. EDIT: I found 2 mistakes. 1) Bug or incomprehension MCC baudrate generator value of frequency. See the post below. 2) My mistake - I didnt switch analog to digital inputs on PORTC because of my thoughts that PIC16F1454 hasn't ADC's so pins are always digital. Now write and read to EEPROM works fine, so that's my read and write functions: #ifndef _APP_I2C_H #define _APP_I2C_H #define RETRY_MAX 100 // define the retry count #define EE24AA256_ADDRESS 0x50 // slave device address I2C_MESSAGE_STATUS status; uint8_t sourceData[16] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF }; uint8_t savedDEVData[16]; //Declarations void I2C_write_byte( uint8_t DEV_address, // slave device address uint16_t DEV_data_address, // starting EEPROM address uint8_t *pData, //first byte of data to write uint16_t nCount); //number of bytes to write //Call example: //I2C_write_byte(EE24AA256_ADDRESS, 0x0010, sourceData, 16); void I2C_read_byte( uint8_t DEV_address, // slave device address uint16_t DEV_data_address, uint8_t *pData, uint16_t nCount); //Call example: //I2C_read_byte(EE24AA256_ADDRESS, 0x0010, savedDEVData, 16); #endif //_I2C_H #include #include #include "i2c/i2c.h" #include "app_i2c.h" #include "system.h" /*============================================================================= * * Write to I2C * *===========================================================================*/ void I2C_write_byte( uint8_t DEV_address, // slave device address uint16_t DEV_data_address, // starting data address uint8_t *pData, //first address of source data uint16_t nCount) //number of bytes to write { uint8_t writeBuffer[3]; //2 bytes of DEV_data_address + 1 byte data uint16_t timeOut; uint16_t counter; uint8_t *pD; pD = pData; status = I2C_MESSAGE_PENDING; for (counter = 0; counter < nCount; counter++) { writeBuffer[0] = (DEV_data_address >> 8); // high address writeBuffer[1] = (uint8_t)(DEV_data_address); // low low address writeBuffer[2] = *pD++; // data to be written timeOut = 0; while(status != I2C_MESSAGE_FAIL) { // write one byte to DEV (3 is the number of bytes to write) I2C_MasterWrite(writeBuffer, 3, DEV_adress, &status); // wait for the message to be sent or status has changed. // in I2C_MasterWrite - MasterTRBInsert we can find: // PIR1bits.SSP1IF = true; which trigger the first interrupt while(status == I2C_MESSAGE_PENDING); if (status == I2C_MESSAGE_COMPLETE) break; // check for max retry and skip this byte if (timeOut == RETRY_MAX) { status == I2C_MESSAGE_FAIL; break; } else timeOut++; } if (status == I2C_MESSAGE_FAIL) break; else DEV_data_address++; }//end "for" number of bytes to write return; }//end of DEV_write /*============================================================================= * * Read from I2C Device * *===========================================================================*/ void I2C_read_byte( uint8_t DEV_address, // slave device address uint16_t DEV_data_address, // starting data address uint8_t *pData, //first address of saved data from DEV uint16_t nCount) //number of bytes to write { I2C_MESSAGE_STATUS status; uint8_t writeBuffer[3]; uint16_t timeOut; uint16_t counter; uint8_t *pD, ret; pD = pData; status = I2C_MESSAGE_PENDING; //WRITE data address to DEV which we wanna read for (counter = 0; counter < nCount; counter++) { // build the write buffer first writeBuffer[0] = (DEV_data_address >> 8); // high address writeBuffer[1] = (uint8_t)(DEV_data_address); // low low address timeOut = 0; while(status != I2C_MESSAGE_FAIL) { // write one byte to DEV (2 is the count of bytes to write) I2C_MasterWrite(writeBuffer, 2, DEV_address, &status); // wait for the message to be sent or status has changed. while(status == I2C_MESSAGE_PENDING); if (status == I2C_MESSAGE_COMPLETE) break; // check for max retry and skip this byte if (timeOut == RETRY_MAX) { status == I2C_MESSAGE_FAIL; break; } else timeOut++; } if (status == I2C_MESSAGE_COMPLETE) { // this portion will read the byte from the memory location. timeOut = 0; while(status != I2C_MESSAGE_FAIL) { // write one byte to DEV(2 is the count of bytes to write) I2C_MasterRead(pD, 1, DEV_address, &status); // wait for the message to be sent or status has changed. while(status == I2C_MESSAGE_PENDING); if (status == I2C_MESSAGE_COMPLETE) break; // check for max retry and skip this byte if (timeOut == RETRY_MAX) { status == I2C_MESSAGE_FAIL; break; } else timeOut++; } } // exit if the last transaction failed if (status == I2C_MESSAGE_FAIL) break; pD++; DEV_data_address++; } return; } |
|
相关推荐
5个回答
|
|
|
MCC为我提供了400千赫的设置:我改变了:像数据表一样。信号仍然不代表。
以上来自于百度翻译 以下为原文 MCC offer me to set for 400kHz: // Baud Rate Generator Value: SSPADD 4; SSP1ADD = 0x04; I changed: SSP1ADD = 0x09; like in datasheet. And the signals still not represent. |
|
|
|
|
|
我在MCC中发现了一个错误,它返回了波特率生成器不正确的结果:Video https://yadi.sk/i/u n7FbHJuFnapI得到了CLK和数据信号,现在SSP1ADD=0x1D;。
以上来自于百度翻译 以下为原文 I found the bug in MCC which returns not correct result of baudrate genereator: Video https://yadi.sk/i/__n7FbHJuFnap I got CLK and DATA signals now with SSP1ADD = 0x1D;. |
|
|
|
|
|
什么版本的MCC?如果这是最新的你需要贴在MCC论坛,所以MCC团队可以意识到这一点。
以上来自于百度翻译 以下为原文 What version of MCC? If it is the latest you need to post in the MCC forum so MCC team can be aware of it. |
|
|
|
|
|
我以后再写信给你。我再次失去了CLK数据信号,有点不安。经过良好的周期性I2C包,我什么也看不见。
以上来自于百度翻译 以下为原文 Ill write later about it. Ive lost CLK DATA signals again and a bit upset. After a good periodic i2c packets I see nothing. |
|
|
|
|
|
总结我发现了2个错误。1)错误理解MCC波特率发生器的频率值。2)我的错误-我没有在PORTC上把模拟转换为数字输入,因为我认为PIC16F1454没有ADC,所以引脚总是数字的。现在写和读EEPROM工作正常。2功能在第一篇文章中。
以上来自于百度翻译 以下为原文 Summary I found 2 mistakes. 1) Bug or incomprehension MCC baudrate generator value of frequency. 2) My mistake - I didnt switch analog to digital inputs on PORTC because of my thoughts that PIC16F1454 hasn't ADC's so pins are always digital. Now write and read to EEPROM works fine. 2 functions in first post. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 10:43 , Processed in 0.991514 second(s), Total 80, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2114