• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   3 Anonymous Users






Re: 使用PIC18F4550軟體I2C讀不到EEPROM資料的問題
#4
版主
版主


查看用戶資訊
不合格!

要完整的 SCL & SDA 的波形才可以切要涵蓋 Start 到 Stop Condition,請重送。

發表於: 2008/10/16 10:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 使用PIC18F4550軟體I2C讀不到EEPROM資料的問題
#3
初級會員
初級會員


查看用戶資訊
感謝版主的回覆~

我是利用萬用燒錄器,將EEPROM中的資料讀出~
合對EEPROM中的位置,是否與寫入之值相同~
所以才得知,資料有寫進EEPROM之中~

版主,我以分析儀的圖擷取出也以上傳了~
謝謝~

如果各位大大 有相關的意見,也拜託給我一點建議~謝謝~

Attach file:



jpg  (0.00 KB)


jpg  (0.00 KB)


發表於: 2008/10/16 10:04
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 使用PIC18F4550軟體I2C讀不到EEPROM資料的問題
#2
版主
版主


查看用戶資訊
有個問題先請教一下,你怎樣確定你的資料有寫到 EEPROM 中?

可以的話貼一下你所抓到的波形這樣比較容易,程式那麼長單用看的很難除錯。

發表於: 2008/10/16 9:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


使用PIC18F4550軟體I2C讀不到EEPROM資料的問題
#1
初級會員
初級會員


查看用戶資訊
各位大大~
我用了AN997還有之前版上一位前輩的範例~整合一個程式~
已經成功的將EEPROM寫入資料了~
可是目前卻是遇到讀不出資料的問題~

貼上讀取EEPROM的程式~還請各位大大幫忙~
程式中是否出錯~

==============================

/*=============================================
腳位定義: RA0 ===> SCL
RA1 ===> SDA
PORTD ===> All LED
==============================================*/
#define SW3 RA4
#define SW2 RB2
#define SCL RA0 //PORTA.RA0==>SCL
#define SDA RC0 //PORTA.RA1==>SDA
#define SDA_TRIS TRISC0 //SDA tris bit, PORTA pin 1
#include <pic18.h> //#include <pic18f4550.h>


void init(void);
void delay(void);

void I2C_start(void);
void I2C_write(void);
void I2C_read(void);
void I2C_stop(void);
void I2C_RecData(void);

unsigned char I2cRecData( void );

unsigned int ee_data;
unsigned int ee_temp;
unsigned int address;
unsigned char address_High;
unsigned char address_Low;

unsigned char temp;

/*==============================================
Main Program
==============================================*/
void main(void)
{

unsigned char temp1;
unsigned char i;
init();
while(1)
{
if(!SW3)
{

Delay_x_mS(100);
I2C_read();

}

}

}


/*==============================================
init
==============================================*/
void init(void)
{
TRISA = 0b00010000; //設定PortA
TRISD = 0b00000000; //設定PortD
TRISB = 0b00000100; //設定PortB
PORTD = 0x00; //清除PORTD

}

/*==============================================
I2C_start
==============================================*/
void I2C_start(void)
{

SDA_TRIS = 1; // Ensure SDA is high
SCL = 1; // Ensure SCL is high
SDA = 1;
SDA_TRIS = 0; // Configure SDA as an output
SDA = 0; // Pull SDA low
SCL = 0; // Pull SCL low



}

/*==============================================
I2C_data
==============================================*/

void I2C_data( unsigned char Data )
{
signed char i;
SDA_TRIS = 0;


for( i =7;i>=0;i-- )
{
SCL = 0;

temp = ( Data >> i) & 0x01;
SDA = temp;
SCL = 1;

}
SDA_TRIS = 1;

NOP();
SCL = 0;
NOP();
SCL = 1;
NOP();
SCL = 0;

SDA_TRIS = 0;
}



/*==============================================
I2C_address
==============================================*/
void I2C_address(unsigned char SlaveAddr, unsigned char Mode) // Write : Mode = 0, Read : Mode = 1
{
unsigned char Addr;
signed char i;
SDA_TRIS = 0;
SCL = 0;
Addr = SlaveAddr | Mode;
SDA = 0;
for( i=7;i>=0;i-- )
{

SCL = 0;

temp = ( Addr >> i ) & 0x01;
SDA = temp;

SCL = 1;

}

SDA_TRIS = 1;

SCL = 0;
NOP();
NOP();
SCL = 1;
NOP();
SCL = 0;
SDA_TRIS = 0;
SDA = 0;

}

/*==============================================
I2C_stop
==============================================*/
void I2C_stop(void)
{

SCL = 0; // Ensure SCL is low
SDA_TRIS = 0; // Configure SDA as an output
SDA = 0; // Ensure SDA low
SCL = 1; // Pull SCL high
SDA = 1;
SDA_TRIS = 1; // Allow SDA to be pulled high

}



/*==============================================
I2C_write
==============================================*/
void I2C_write(void)
{

signed char i;
signed char u;
i=0x20;
I2C_start();
NOP();
I2C_address(0xA0,0);
NOP();
I2C_data(0x01);
NOP();
I2C_data(0x00);
NOP();
for(u=63;u>=0;u--)
{
NOP();
I2C_data(i);
i++;

}

NOP();
NOP();

I2C_stop();



}

/*==============================================
I2C_read
==============================================*/
void I2C_read(void)
{
unsigned char temp1;

I2C_start();
NOP();
I2C_address(0xA0,0);
NOP();
I2C_data(0x00);
NOP();
I2C_data(0x02);
NOP();
I2C_start();
NOP();
I2C_address(0xA0,1);
NOP();
temp1 = I2cRecData();

NOP();
I2C_stop();

PORTD = temp1;
Delay_x_mS(2000);
}

/*==============================================
I2C_recdata
==============================================*/
unsigned char I2cRecData( void )
{

signed char i;
unsigned char temp2;
temp2 = 0x00;
SDA_TRIS = 1;
NOP();
for( i=7;i>=0;i-- )
{
SCL = 0;
NOP();NOP();
SCL = 1;
NOP();NOP();
temp2 << 1;
NOP();NOP();
if(SDA==1) temp2 |= 0x01;
NOP();NOP();
}
SDA_TRIS = 0;

SCL = 0;
SCL = 1;
SDA = 1;



SDA = 0;
SCL = 0;
return temp2;

}


==================================

目前的問題,讀不到EEPROM中資料~

用邏輯分析儀看波形,所有的波形都有出來~~

但是在最後的讀取部分,SDA大部份都是低準位,完全沒有丟出EEPROM之中的0x55~

還請各位大大幫忙~謝謝~

發表於: 2008/10/15 22:02
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... ]

教育訓練中心

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