• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: I2C 無法正確動作..
#6
新會員
新會員


查看用戶資訊
Mike 大大
我也遇到類似的問題
i2cread()得到的值為0xFF
在示波器上發現bq27200都不會回我ACK
不知道你有沒有遇過類似問題

發表於: 2009/10/28 9:51
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: I2C 無法正確動作..
#5
初級會員
初級會員


查看用戶資訊
To All,

謝謝大大們的指教,我己經可以正確讀出 Battery 的相關數值
了, Thanks.

Best Regards
Mike

發表於: 2006/7/28 13:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: I2C 無法正確動作..
#4
初級會員
初級會員


查看用戶資訊
各位版大您們好:

小弟在 "勇於發言"大大的提示下,一步步的修改程式,並以示波器來量測 I2C 的訊號,發現雖然我的波形與電池接上 PDA並以PDA之控制台POWER程式執行後所測量的波形相去不遠,但是總是得不到正確的值及在 LED 上總是顯示為 0xFF 的訊息,不清楚為何會如此,而且我是根據 Bq27200 的 DATASHEET去撰寫相對的 I2C protocol , 以下是修改後的程式碼,請各位大大給予指教, 謝謝!!

#include <p18cxxx.h>
#include <i2c.h>

void main()
{
unsigned char value;
int i;

TRISD = 0;
TRISC = 0x18; // RC3-4 are inputs
SSPSTAT = 0x80; // slew rate disabled for Standard Speed mode (100 kHz and 1 MHz)
SSPCON1 = 0x38; // I2C Master mode, clock = FOSC / (4 * (SSPADD+1))
SSPCON2 = 0x00; // not a lot

//try to read battery info from I2C bus..

OpenI2C(MASTER,SLEW_ON); //Setup I2C master mode
SSPADD=39; // (Battery Internal Fsoc) 100k = (18f452 internal Osc.) 16MHz / ((39+1) * 4)

while(1) {

//delay for a while..
for(i=0;i<10;i++)
F_Delay ( 10000 );

IdleI2C();
StartI2C();
while ( SSPCON2bits.SEN );
PIR1bits.SSPIF=0;
Delay1KTCYx(10);

WriteI2C(0xAA); // Addr: 7bit + R/W: 0 -> Write => leftshift(0x55)| 0 (write bit) = 0xAA
Delay1KTCYx(10);

while (!PIR1bits.SSPIF);
PIR1bits.SSPIF=0;

//for example: access battery life percentage(command addr = 0x0B , 1 byte read)
WriteI2C(0x0B);//command register adress
while (!PIR1bits.SSPIF);
PIR1bits.SSPIF=0;
Delay1KTCYx(10);

RestartI2C();
while ( SSPCON2bits.RSEN );
PIR1bits.SSPIF=0;

WriteI2C(0xAB); // Addr: 7bit + R/W: 1 -> Read => leftshift(0x55)| 1 (write bit) = 0xAB
while (!PIR1bits.SSPIF);
PIR1bits.SSPIF=0;
Delay1KTCYx(10);

value = ReadI2C();
PORTD = value; //show data to LED..

NotAckI2C();

Delay1KTCYx(10);
StopI2C();
while ( SSPCON2bits.PEN );

};
}

PS:) Bq27200 I2C 1-byte read protocol:

START -- ADDR[6:0] -- 0{write} -- ACK -- CMD[7:0] -- ACK -- RESTART -- ADDR[6:0] -- 1{read} -- ACK -- DATA[7:0] -- NACK -- STOP
==>(write/read only 1 bit)/* 1 BYTE READ */

Command Register Address 0x0b: RSOC Relative State-of-Charge
=================================
RSOC reports the nominal available capacity as a percentage of the last measured discharge value (LMD). The
equation is:
RSOC (%) = 100 * NAC(Nominal Available Capacity)/LMD(Last
Measured Discharge)

The host system has read-only access to this register.
........

發表於: 2006/7/27 12:17
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: I2C 無法正確動作..
#3
初級會員
初級會員


查看用戶資訊
感謝 powmien 大大:

我將試著用示波器來確認主控端的 SCL , SDA 的波形是否正確再一步步的除錯使雙方的 Protocol 可以 Match 讀值 ,謝謝
!!

發表於: 2006/7/20 13:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: I2C 無法正確動作..
#2
高級會員
高級會員


查看用戶資訊
先跟slave 隔開,確定你的i2c scl sda 波形正常,再跟slave connect...

master scl sda 都為output, 接收ack時 sda 設成input

start/stop bit 不算.. 一筆資料( 1 byte ) scl 會有九個pulse

start bit 是 sda 先low 一段時間 scl 再low..

data sda 先hi scl 再hi , scl low sda 再low 這樣傳8 bits

接收ack/nak...

stop bit scl先hi sda 再hi... over

大約這樣... 先確定波形ok...

發表於: 2006/7/19 17:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


I2C 無法正確動作..
#1
初級會員
初級會員


查看用戶資訊
版主您好:
  
  小弟用18F452 的 RC3(SCL),RC4(SDA)與 外部 BATTERY (Bq27200) 的 SCL, SDA線路相接, 透過使用手冊的說明18F452其內部本身具有上升電阻,並且使用 I2C 的 MASTER 範例程式 來調試 I2C 的傳輸狀況(以LED秀出),但是我發現在傳送開始條件 (SSPCON2bits.SEN = 1;), 然後再判斷 PIR1bits.SSPIF 的回傳值是否成功,就永遠為 0 ,不知是何原因,以下為簡單的
Sample code list..

#include <p18cxxx.h>

void main()
{
F_Initial();
F_I2C_START(); //卡住,無法進入下一行指令,並看見灯亮..
PORTD = 0XAA;
if (F_I2C_Send_Address(I2C_Device1,UC_I2C_CMD))
...
}

void F_Initial(void)
{
TRISD = 0;
LATD = 0;
TRISCbits.TRISC3 = 0;
TRISCbits.TRISC4 = 0 ;
SSPSTATbits.SMP = 1;
SSPSTATbits.CKE = 0;
SSPCON1 = 0x38;
SSPADD = 0x30;
}

void F_I2C_START(void)
{
SSPCON2bits.SEN = 1;
while(!F_I2C_WAIT()); //永遠等待,無法跳出迴圈
}

unsigned char F_I2C_WAIT(void)
{
if ( PIR1bits.SSPIF )
{
PIR1bits.SSPIF = 0;
return (1);
}
else
return (0);
}

本程式為 PIC18Fxx2微控制器實習模組的I2C master 範例程式,但我皆無法在 START BIT 之後無法繼續下去,不知是否在外掛電池(Bq27200)與實驗板是否需要注意什麼事項,否則為何我皆無法正確動
作,謝謝大大的指教 !!

發表於: 2006/7/19 11:33
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------