becomeAGeneral 发表于 2024-6-8 15:40:55

主控芯片是stc8G,poe芯片是MP3924,为什么我读取POE芯片的ADC通道的寄存器值一直是FF

#include"STC8h.h"
#include"usart.h"
#include"delay.h"
#include"stdio.h"


#include "intrins.h"



sbit    SDA   =   P1^4;
sbit    SCL   =   P1^5;

unsigned charRegister_Data;

bit busy;

void I2C_Isr() interrupt 24
{
   // _push_(P_SW2);
    P_SW2 |= 0x80;
    if (I2CMSST & 0x40)
    {
      I2CMSST &= ~0x40;                     //?????
      busy = 0;
    }
   // _pop_(P_SW2);
}

void Start()
{
    busy = 1;
    I2CMSCR = 0x81;                           //??START??
    while (busy);
}

void SendData(char dat)
{
    I2CTXD = dat;                               //?????????
    busy = 1;
    I2CMSCR = 0x82;                           //??SEND??
    while (busy);
                usart_send_char(busy);
}

void RecvACK()
{
    busy = 1;
    I2CMSCR = 0x83;                           //???ACK??
    while (busy);
}

char RecvData()
{
    busy = 1;
    I2CMSCR = 0x84;                           //??RECV??
    while (busy);
    return I2CRXD;
}

void SendACK()
{
    I2CMSST = 0x00;                           //??ACK??
    busy = 1;
    I2CMSCR = 0x85;                           //??ACK??
    while (busy);
}

void SendNAK()
{
    I2CMSST = 0x01;                           //??NAK??
    busy = 1;
    I2CMSCR = 0x85;                           //??ACK??
    while (busy);
}

void Stop()
{
    busy = 1;
    I2CMSCR = 0x86;                           //??STOP??
    while (busy);
}

void Delay()
{
    int i;

    for (i=0; i<3000; i++)
    {
      _nop_();
      _nop_();
      _nop_();
      _nop_();
    }
}

void main()
{
                unsigned char Counter=10;

    P0M0 = 0x00;
    P0M1 = 0x00;
    P1M0 = 0x00;
    P1M1 = 0x00;
    P2M0 = 0x00;
    P2M1 = 0x00;
    P3M0 = 0x00;
    P3M1 = 0x00;
    P4M0 = 0x00;
    P4M1 = 0x00;
    P5M0 = 0x00;
    P5M1 = 0x00;

    P_SW2 = 0x80;

//        P10=1;P11=0;P16=1;P35=0; //success
       
    I2CCFG = 0xe0;                           
    I2CMSST = 0x00;
    EA = 1;
                Register_Data=0;//register_data_
                usart_init();
               
                                  Start();         //open IIC                        
    SendData(0x60);      //transmit address + write   0x60                          
    RecvACK();
    SendData(0x0F);          //transmithigh address of storage               
    RecvACK();
                SendData(0x00);          //transmithigh address of storage               
    RecvACK();
    Stop();                        //stop            

                Delay10us(100);
               
                while(1)
                {
               
        //the second data_ is valid
    Start();                        //start            
    SendData(0x60);                  //device   address +write         
    RecvACK();
    SendData(0x43);               //register00dat of high               
    RecvACK();
    Start();                        //prepare for read the storage 'sdat            
    SendData(0x61);                //read the dat from mechine            
    RecvACK();
    Register_Data = RecvData();               
    SendACK();       
                  Register_Data = RecvData();               
    SendACK();
    Counter=RecvData();               
    SendNAK();                                                               
    Stop();
               
                Counter=Counter>>2;
                P10=0;P37=0;        P11=0;P16=0;
          usart_send_char(11);               
                usart_send_char(0x11);       
                usart_send_char(Counter);               
                usart_send_char(Register_Data);
        }

    while (1);
}


神农鼎 发表于 2024-6-8 16:22:40



MP3924 | Quad-Port, IEEE 802.3af/at-Compliant PSE Controller for Power over Ethernet Applications | MPS (monolithicpower.com)

神农鼎 发表于 2024-6-8 16:25:53




I2C 外部加 10K 上拉电阻,
或上电初始化打开内部 4K上拉电阻, 1mS后再操作

becomeAGeneral 发表于 2024-6-11 08:52:34

神农鼎 发表于 2024-6-8 16:25
I2C 外部加 10K 上拉电阻,
或上电初始化打开内部 4K上拉电阻, 1mS后再操作
...

好的我尝试一下谢谢

becomeAGeneral 发表于 2024-6-13 18:49:43

神农鼎 发表于 2024-6-8 16:25
I2C 外部加 10K 上拉电阻,
或上电初始化打开内部 4K上拉电阻, 1mS后再操作
...

您好我有个问题就是我还是无法获取那个状态就算是设置了上拉电阻
页: [1]
查看完整版本: 主控芯片是stc8G,poe芯片是MP3924,为什么我读取POE芯片的ADC通道的寄存器值一直是FF