[問題] stm32F 和 arduino uno I2C 連線問題

作者: polor (波羅兒)   2014-07-26 16:20:50
最近在練習在 stm32f discovery 和 arduino 做 I2C 溝通
1. stm32 部分的 code 為 http://codepad.org/YixZzNv3
2. arduino 的 code 為 http://codepad.org/rtpBBUh3
程式碼都是從網路上抓來修改
碰到奇怪的問題是, 在 stm32 中
while(1){
I2C_start(I2C1, SLAVE_ADDRESS<<1, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode
I2C_write(I2C1, 0x20); // write one byte to the slave
//I2C_write(I2C1, 0x03); // write another byte to the slave
I2C_stop(I2C1); // stop the transmission
//printf("data\n");
}
如果加一個 printf("data\n") , arduino 那邊就會收到訊息
mark掉就不會收到, 我在想是不是 timing 的問題?
只是我嘗試修改 clock 的設定, 似乎結果都一樣
請問問題出在哪?
謝謝
作者: damody (天亮damody)   2014-07-26 17:34:00
盡量不要直接呼叫hal層的函數 printf偷做了很多東西吧
作者: polor (波羅兒)   2014-07-26 19:14:00
我的意思說使用printf卻受到訊息 本來我是沒要用的
作者: easypro   2014-07-27 00:04:00
那應該是設定到跑uart了吧 並非跑i2c狀態
作者: damody (天亮damody)   2014-07-27 13:48:00
抱歉應該跟底層無關 今天你用while送I2C沒有停 肯定GGprintf只是delay用的,總之IIC要給對方有時間處理資料

Links booklink

Contact Us: admin [ a t ] ucptt.com