MAX14915為8通道高邊開(kāi)關(guān)。它支持8通道驅(qū)動(dòng)1A。微控制器兼容型串行外設(shè)接口(SPI)提供對(duì)許多診斷功能的訪問(wèn)。本應(yīng)用筆記提供了C代碼實(shí)現(xiàn)示例,包括設(shè)置、監(jiān)控和診斷功能。
介紹
MAX14915/MAX14916集成8個(gè)高邊開(kāi)關(guān),提供輸出通道數(shù)、限流和診斷功能等特性。MAX14915為八通道高邊開(kāi)關(guān),具有豐富的診斷功能和每通道1A (典型值)電流限值。MAX14916可配置為八通道高邊開(kāi)關(guān)(1A限流)或四通道高邊開(kāi)關(guān)(2A限流)。這些器件具有單獨(dú)的通道熱保護(hù)、用于快速感應(yīng)退磁的內(nèi)部箝位以及用于開(kāi)和關(guān)狀態(tài)的開(kāi)路檢測(cè)。此外,還有一個(gè)集成的發(fā)光二極管(LED)矩陣,可顯示每個(gè)通道的狀態(tài)(開(kāi)/關(guān))以及故障條件。
本應(yīng)用筆記介紹了一系列功能,為MAX14915/6編程提供簡(jiǎn)單且經(jīng)過(guò)驗(yàn)證的解決方案(圖1)。它們是用C語(yǔ)言編寫(xiě)的,應(yīng)該很容易移植到任何常見(jiàn)的微控制器上。有關(guān)MAX14915引腳、工作模式和控制寄存器的詳細(xì)信息,請(qǐng)參考MAX14915數(shù)據(jù)資料。有關(guān)MAX14916引腳、工作模式和控制寄存器的詳細(xì)信息,請(qǐng)參考MAX14916數(shù)據(jù)資料。
本應(yīng)用筆記主要展示了MAX14915的編程,但MAX14916的技術(shù)非常相似。
圖1.MAX14915功能框圖
MAX14915 SPI
MAX14915 SPI命令長(zhǎng)度為16位(8位指令+8位數(shù)據(jù)),CRC禁用,如果使能CRC,則CRC8將增加8位。命令字節(jié)的 2 MSB 是芯片地址位,它們?cè)试S 4 個(gè)芯片共享相同的芯片選擇 (CS) 引腳。 SPI 命令結(jié)構(gòu)如表 1 所示。MAX14915的SPI模式為CPOL = 0 (CLK空閑= 0),CPHA = 0 (上升沿/第一沿對(duì)數(shù)據(jù)進(jìn)行采樣),數(shù)據(jù)/命令需要先以MSB時(shí)鐘。
芯片地址 | 突發(fā)位 |
注冊(cè) - 地址 |
R/W | 數(shù)據(jù) |
---|---|---|---|---|
2 位 A[1:0] |
1 位 BRST[0] |
4 位 R[3:0] MSB 至 LSB |
1 位 RW[0] |
8 位 D[7:0] MSB 至 LSB |
有關(guān)SPI讀寫(xiě)周期以及寄存器表和指令的更多詳細(xì)信息,請(qǐng)參考MAX14915和MAX14916數(shù)據(jù)資料。
圖1所示為MAX14915的主要功能塊。基本上,有8個(gè)輸出通道高邊驅(qū)動(dòng)器、看門(mén)狗和診斷、一個(gè)16個(gè)LED(4x4)矩陣驅(qū)動(dòng)器和邏輯端接口(SPI端口),用于訪問(wèn)所有器件寄存器和硬件標(biāo)志以進(jìn)行診斷。
MAX14915 – 代碼應(yīng)用示例
MAX14915設(shè)計(jì)用于支持終端設(shè)備的工業(yè)應(yīng)用,如需要多個(gè)高邊開(kāi)關(guān)的可編程邏輯控制器(PLC)。支持16通道組隔離的典型應(yīng)用電路采用單個(gè)MAX14483數(shù)字隔離器,如圖2所示。
圖2.16通道高邊開(kāi)關(guān)組隔離。
每個(gè)單獨(dú)的輸出可以驅(qū)動(dòng)高達(dá) 1A 的電流,并具有單獨(dú)的開(kāi)路、過(guò)流和過(guò)溫診斷
為了簡(jiǎn)化需要電流隔離的系統(tǒng),MAX14915支持菊花鏈和尋址SPI模式。
注意: 某些診斷功能僅在直接 SPI 或?qū)ぶ?SPI 模式下可用,但在菊花鏈模式下不可用。詳情請(qǐng)參考MAX14915數(shù)據(jù)資料。
源代碼
本應(yīng)用筆記提供了C源代碼示例,主要提供驅(qū)動(dòng)器功能,用于訪問(wèn)MAX14915中的多個(gè)寄存器,以實(shí)現(xiàn)配置、控制和診斷功能。所有軟件均使用MAX14915評(píng)估板進(jìn)行實(shí)現(xiàn)和測(cè)試。客戶應(yīng)僅將本文檔中的功能用作參考,并根據(jù)其應(yīng)用程序中的微控制器和硬件實(shí)現(xiàn)設(shè)計(jì)自己的固件/軟件。
寄存器地址定義:
#define REG_SetOUT 0x00 #define REG_SetFLED 0x01 #define REG_SetSLED 0x02 #define REG_Interupt 0x03 #define REG_OvlChF 0x04 #define REG_CurrLimF 0x05 #define REG_OwOffChF 0x06 #define REG_OwOnChF 0x07 #define REG_ShtVDDChF 0x08 #define REG_GlobalErr 0x09 #define REG_OwOffEn 0x0a #define REG_OwOnEn 0x0b #define REG_ShtVddEn 0x0c #define REG_Config1 0x0d #define REG_Config2 0x0e #define REG_Mask 0x0f
其他定義:
#define OUT1 0x01 #define OUT2 0x02 #define OUT3 0x04 #define OUT4 0x08 #define OUT5 0x10 #define OUT6 0x20 #define OUT7 0x40 #define OUT8 0x80 #define GLB_ShrtVDD 0x20 #define GLB_OWOnF 0x10 #define GLB_OWOffF 0x08 #define GLB_CurrLim 0x04 #define GLB_OverLdF 0x02 #define GLB_GloblF 0x01 bool CRC_Enabled = true; // if pin CRCEN = high, then this must be true //bool CRC_Enabled = false; // if pin CRCEN = low, then this must be false const int CRC_ERROR = 0xffff;
該測(cè)試程序等待MAX14915,直到它沒(méi)有報(bào)告任何故障,例如在上電MAX14915報(bào)告上電復(fù)位條件之后。接下來(lái),對(duì)MAX14915進(jìn)行初始化,以便報(bào)告任何故障,作為典型上電自檢程序的一部分,二進(jìn)制計(jì)數(shù)器在8個(gè)通道上運(yùn)行并打印故障條件。
void test() { uint8_t ADR = 0; // MAX14915 Chip-Address Allows multiple Chips with 1 Chip-Select uint16_t loop_count = 0; // Check status, only continue if All OK. uint16_t fault = 0xffff; while (fault != 0) // Halt until MAX14915 has no faults { fault = MAX14915_Init(ADR); if ( (fault) != 0) MAX14915_Identify_Error(ADR, fault); // check for errors if any bit is set } // Writes a binary counter to the 8 Ports // Checks for any errors and prints them while (1) { printf("Writing %i\r\n", loop_count); uint16_t w_result = MAX14915_write_register(ADR, REG_SetOUT, loop_count); w_result = w_result & 0x3fff; // ignore the 2 MSBs, they're not used printf("W-Result 0x%04x\r\n", w_result); if ( (w_result) != 0) MAX14915_Identify_Error(ADR, w_result); // only check if any bit is set delay_ms(100); loop_count++; if (loop_count > 255) loop_count = 0; } }
這些是初始化和使用MAX14915所需的功能,包括寄存器讀寫(xiě)操作、CRC代碼生成和解碼以及錯(cuò)誤標(biāo)志輪詢。
//******************************************************************** //* //* Function: MAX14915_Init //* Description: Initialize MAX14915 //* //* Input: //* Chip_Address: Chip address selected by pins A1 and A0 //* //* Output, none //* Initializes the device after power-up //* //* if CRC is enabled, then crc5 is sent accordingly //* //********************************************************************/ uint16_t MAX14915_Init(uint8_t Chip_Address) { // ********************************************************************************** // * D07 * D06 * D05 * D04 ** D03 * D02 * D01 * D00 * // * ComErrM *SuplErrM * VddOKM * ShtVddM ** OWOnM * OWOffM * OWOffM * OverLdM * // * 1 * 0 * 0 * 0 ** 0 * 0 * 0 * 0 * // ********************************************************************************** // -> 0x80 // All warnings enabled, just Watchdog off uint16_t result = MAX14915_write_register(Chip_Address, REG_Mask, 0x80); // ********************************************************************************** // * D07 * D06 * D05 * D04 ** D03 * D02 * D01 * D00 * // * LEDCLim * FLatchEn*FiltrLong*FFilterEn**FLEDStr1 *FLEDStr0 * SLEDSet * FLEDSet * // * 0 * 1 * 0 * 1 ** 0 * 0 * 0 * 0 * // ********************************************************************************** // -> 0x50 // Enable Status and Fault LEDs // Keep Fault-Latch and Filter-Blanking on result |= MAX14915_write_register(Chip_Address, REG_Config1, 0x50); // enable Open-Wire when off detection on all Channels // this only works if a load is connected on all channels // Maybe should be handled by the Application? result |= MAX14915_write_register(Chip_Address, REG_OwOffEn, 0xff); // enable Open-Wire when on detection on all Channels // this only works if a load is connected on all channels // Maybe should be handled by the Application? result |= MAX14915_write_register(Chip_Address, REG_OwOnEn, 0xff); // enable Short to VDD detection on all Channels // this only works if a load is connected on all channels // Maybe should be handled by the Application? result |= MAX14915_write_register(Chip_Address, REG_ShtVddEn, 0xff); return result & 0x3fff; // discard the 2 MSBs, since they're unused } //******************************************************************** //* //* Function: MAX14915_write_register //* Description: Write one Register to MAX14915 //* //* Input: //* Chip_Address: Chip address selected by pins A1 and A0 //* Register-Address take from definitions in header-file //* data Data to be written into the register //* //* Output, 16bit result: //* MSB 8-bits = Global Error uint8_t //* LSB 8-bits = Fault bits F8 to F1 //* //* if CRC is enabled, then crc5 is sent accordingly //* //********************************************************************/ uint16_t MAX14915_write_register(uint8_t Chip_Address, uint8_t Register_Address, uint8_t data) { // Construct the SPI uint8_t to transmit uint8_t CHIP_ADR = (uint8_t) (Chip_Address<<6); // 2 MSBs are the Chip Address (A1 and A0) uint8_t BRST = 0; // 0 = no burst read; 1 = burst read -> 0x20 to set this bit uint8_t R_ADR = (uint8_t) (Register_Address<<1); // Register Address uint8_t command = (uint8_t) (CHIP_ADR | BRST | R_ADR | 1); // construct SPI Command uint8_t. LSB = 1 for Write-Command // END Construct the SPI uint8_t to transmit MAX14915_CS_Low(); // Write Command-uint8_t, Receive the Global Error uint8_t at the same time uint8_t GLOB_ERROR = MAX14915_SPI_RW_8bit(command); // Write Data-uint8_t, Receive the Individual Fault-Bits at the same time uint8_t FAULT_BITS = MAX14915_SPI_RW_8bit(data); if (CRC_Enabled == true) { uint8_t crc5_checksum; crc5_checksum = MAX14915_crc5_encode_2byte(command, data); MAX14915_SPI_RW_8bit(crc5_checksum); } MAX14915_CS_High(); return (uint16_t) ((GLOB_ERROR << 8) | FAULT_BITS);; } //******************************************************************** //* //* Function: MAX14915_read_register //* Description: Read one Register from MAX14915 //* //* Input: //* Chip_Address: Chip address selected by pins A1 and A0 //* Register-Address take from definitions in header-file //* data Data to be written into the register //* //* //* Output, 16bit result: //* MSB 8-bits = Global Error uint8_t //* LSB 8-bits = Register content 8-bits //* //* if CRC is enabled and there was a CRC error, then Output is CRC_ERROR //* //********************************************************************/ uint16_t MAX14915_read_register (uint8_t Chip_Address, uint8_t Register_Address) { // Construct the SPI uint8_t to transmit uint8_t CHIP_ADR = (uint8_t) (Chip_Address<<6); // 2 MSBs are the Chip Address (A1 and A0) uint8_t BRST = 0; // 0 = no burst read; 1 = burst read -> 0x20 to set this bit uint8_t R_ADR = (uint8_t) (Register_Address<<1); // Register Address uint8_t command = (uint8_t) (CHIP_ADR | BRST | R_ADR); // construct SPI Command uint8_t. LSB = 0 for Read-Command // END Construct the SPI uint8_t to transmit MAX14915_CS_Low(); // Write Command-uint8_t, Receive the Global Error uint8_t at the same time uint8_t GLOB_ERROR = MAX14915_SPI_RW_8bit(command); GLOB_ERROR = GLOB_ERROR & 0x3f; // Discard the 2 MSBs, they're not used // Write Data-uint8_t, Receive the Individual Fault-Bits at the same time uint8_t data = MAX14915_SPI_RW_8bit(0); if (CRC_Enabled == true) { uint8_t crc5_read; uint8_t crc5_calc; crc5_calc = MAX14915_crc5_decode_2byte(GLOB_ERROR, data); crc5_read = MAX14915_SPI_RW_8bit(MAX14915_crc5_encode_2byte(command,0)); if (crc5_read != crc5_calc) System_Handle_CRC_Error(Chip_Address); } MAX14915_CS_High(); return (uint16_t) ((GLOB_ERROR << 8) | data); } //******************************************************************** //* //* Function: MAX14915_crc5encode_2byte //* Description: Generates CRC5 byte for 2 byte-Command //* this is needed for WRITE commands //* //* Input: //* byte1: Usually Command Byte //* byte2: Byte written to MAX14915 //* //* Output, 8bit result: //* CRC5 of the 2 Bytes //* //********************************************************************/ uint8_t MAX14915_crc5_encode_2byte(uint8_t byte1, uint8_t byte2) { uint8_t crc5_start = 0x1f; uint8_t crc5_poly = 0x15; uint8_t crc_result = crc5_start; // byte1 for (int i=0; i<8; i++) { if( ((( byte1>>(7-i) )&0x01) ^ ((crc_result & 0x10)>>4)) > 0 ) { crc_result = (uint8_t) (crc5_poly ^ ((crc_result<<1) & 0x1f)); } else { crc_result = (uint8_t)((crc_result<<1) & 0x1f); } } // END byte1 // byte2 for (int i=0; i<8; i++) { if( ((( byte2>>(7-i) )&0x01) ^ ((crc_result & 0x10)>>4)) > 0 ) { crc_result = (uint8_t) (crc5_poly ^ ((crc_result<<1) & 0x1f)); } else { crc_result = (uint8_t)((crc_result<<1) & 0x1f); } } // END byte2 // 3 extra bits set to zero uint8_t uint8_t3=0x00; for (int i=0; i<3; i++) { if( ((( uint8_t3>>(7-i) )&0x01) ^ ((crc_result & 0x10)>>4)) > 0 ) { crc_result = (uint8_t) (crc5_poly ^ ((crc_result<<1) & 0x1f)); } else { crc_result = (uint8_t)((crc_result<<1) & 0x1f); } } // END 3 extra bits set to zero return crc_result; } //******************************************************************** //* //* Function: MAX14915_crc5_decode_2byte //* Description: Decodes CRC5 byte for 2 byte-Command //* this is needed for READ commands //* //* Input: //* byte1: Usually Command Byte //* byte2: byte read from MAX14915 //* //* Output, 8bit result: //* CRC5 of the 2 Bytes //* //********************************************************************/ uint8_t MAX14915_crc5_decode_2byte(uint8_t byte1, uint8_t byte2) { uint8_t crc5_start = 0x1f; uint8_t crc5_poly = 0x15; uint8_t crc_result = crc5_start; // BYTE1 for (int i=2; i<8; i++) { if( ((( byte1>>(7-i) )&0x01) ^ ((crc_result & 0x10)>>4)) > 0 ) // IF(XOR(C6;BITAND(D5;2^4)/2^4) { // BITXOR($D$1;BITAND((D5*2);31)) crc_result = (uint8_t) (crc5_poly ^ ((crc_result<<1) & 0x1f)); } else { crc_result = (uint8_t)((crc_result<<1) & 0x1f); } } // END BYTE1 // BYTE2 for (int i=0; i<8; i++) { if( ((( byte2>>(7-i) )&0x01) ^ ((crc_result & 0x10)>>4)) > 0 ) // IF(XOR(C6;BITAND(D5;2^4)/2^4) { // BITXOR($D$1;BITAND((D5*2);31)) crc_result = (uint8_t) (crc5_poly ^ ((crc_result<<1) & 0x1f)); } else { crc_result = (uint8_t)((crc_result<<1) & 0x1f); } } // END BYTE2 // 3 extra bits set to zero uint8_t byte3=0x00; for (int i=0; i<3; i++) { if( ((( byte3>>(7-i) )&0x01) ^ ((crc_result & 0x10)>>4)) > 0 ) // IF(XOR(C6;BITAND(D5;2^4)/2^4) { // BITXOR($D$1;BITAND((D5*2);31)) crc_result = (uint8_t) (crc5_poly ^ ((crc_result<<1) & 0x1f)); } else { crc_result = (uint8_t)((crc_result<<1) & 0x1f); } } // END 3 extra bits set to zero return crc_result; } //******************************************************************** //* //* Function: MAX14915_Identify_Error //* Description: This should be called if one of the Global-Error bits //* or Fault bits is set //* This function identifies the error and calls //* //* Input: //* uint16_t: MS-uint8_t = Global Errors from SPI transfer //* LS-uint8_t = Channel Fault bits from SPI transfer //* //* Output: //* none, will call System Level function to handle the error //* //********************************************************************/ void MAX14915_Identify_Error(uint8_t Chip_Address, uint16_t ERROR_INFO) { uint8_t GlobalERR = (uint8_t) ((ERROR_INFO>>8) & 0xff); // MSB 8-bits = Global Error uint8_t uint8_t CH_FAULT = (uint8_t) ((ERROR_INFO) & 0xff); // LSB 8-bits = Fault bits F8 to F1 if ((GlobalERR & GLB_GloblF) != 0) System_Handle_Global_fault(Chip_Address); // If no Channel Fault, then no further checking is needed: if (CH_FAULT == 0) return; // if only one single fault exists, then Error-Type is already known by Global_Error_uint8_t if ( (CH_FAULT == OUT1) || (CH_FAULT == OUT2) || (CH_FAULT == OUT3) || (CH_FAULT == OUT4) || (CH_FAULT == OUT5) || (CH_FAULT == OUT6) || (CH_FAULT == OUT7) || (CH_FAULT == OUT8) ) { uint8_t ch_number = MAX14915_decode_channel_number(CH_FAULT); if ((GlobalERR & GLB_ShrtVDD) != 0) System_Handle_Short_to_VDD_CH(ch_number, Chip_Address); if ((GlobalERR & GLB_OWOnF) != 0) System_Handle_OpenWire_CH(ch_number, Chip_Address); if ((GlobalERR & GLB_OWOffF) != 0) System_Handle_OpenWire_CH(ch_number, Chip_Address); if ((GlobalERR & GLB_CurrLim) != 0) System_Handle_Current_Limit_CH(ch_number, Chip_Address); if ((GlobalERR & GLB_OverLdF) != 0) System_Handle_Overload_CH(ch_number, Chip_Address); } else { // there is more than 1 error present // so we need to check each channel // first read each Error Register: uint16_t OvlChF = MAX14915_read_register (Chip_Address, REG_OvlChF); uint16_t CurrLim = MAX14915_read_register (Chip_Address, REG_CurrLimF); uint16_t OwOffChF = MAX14915_read_register (Chip_Address, REG_OwOffChF); uint16_t OwOnChF = MAX14915_read_register (Chip_Address, REG_OwOnChF); uint16_t ShtVDDChF = MAX14915_read_register (Chip_Address, REG_ShtVDDChF); if ((OvlChF & OUT1) != 0) System_Handle_Overload_CH(1, Chip_Address); if ((OvlChF & OUT2) != 0) System_Handle_Overload_CH(2, Chip_Address); if ((OvlChF & OUT3) != 0) System_Handle_Overload_CH(3, Chip_Address); if ((OvlChF & OUT4) != 0) System_Handle_Overload_CH(4, Chip_Address); if ((OvlChF & OUT5) != 0) System_Handle_Overload_CH(5, Chip_Address); if ((OvlChF & OUT6) != 0) System_Handle_Overload_CH(6, Chip_Address); if ((OvlChF & OUT7) != 0) System_Handle_Overload_CH(7, Chip_Address); if ((OvlChF & OUT8) != 0) System_Handle_Overload_CH(8, Chip_Address); if ((CurrLim & OUT1) != 0) System_Handle_Current_Limit_CH(1, Chip_Address); if ((CurrLim & OUT2) != 0) System_Handle_Current_Limit_CH(2, Chip_Address); if ((CurrLim & OUT3) != 0) System_Handle_Current_Limit_CH(3, Chip_Address); if ((CurrLim & OUT4) != 0) System_Handle_Current_Limit_CH(4, Chip_Address); if ((CurrLim & OUT5) != 0) System_Handle_Current_Limit_CH(5, Chip_Address); if ((CurrLim & OUT6) != 0) System_Handle_Current_Limit_CH(6, Chip_Address); if ((CurrLim & OUT7) != 0) System_Handle_Current_Limit_CH(7, Chip_Address); if ((CurrLim & OUT8) != 0) System_Handle_Current_Limit_CH(8, Chip_Address); if ((OwOffChF & OUT1) != 0) System_Handle_OpenWire_CH(1, Chip_Address); if ((OwOffChF & OUT2) != 0) System_Handle_OpenWire_CH(2, Chip_Address); if ((OwOffChF & OUT3) != 0) System_Handle_OpenWire_CH(3, Chip_Address); if ((OwOffChF & OUT4) != 0) System_Handle_OpenWire_CH(4, Chip_Address); if ((OwOffChF & OUT5) != 0) System_Handle_OpenWire_CH(5, Chip_Address); if ((OwOffChF & OUT6) != 0) System_Handle_OpenWire_CH(6, Chip_Address); if ((OwOffChF & OUT7) != 0) System_Handle_OpenWire_CH(7, Chip_Address); if ((OwOffChF & OUT8) != 0) System_Handle_OpenWire_CH(8, Chip_Address); if ((OwOnChF & OUT1) != 0) System_Handle_OpenWire_CH(1, Chip_Address); if ((OwOnChF & OUT2) != 0) System_Handle_OpenWire_CH(2, Chip_Address); if ((OwOnChF & OUT3) != 0) System_Handle_OpenWire_CH(3, Chip_Address); if ((OwOnChF & OUT4) != 0) System_Handle_OpenWire_CH(4, Chip_Address); if ((OwOnChF & OUT5) != 0) System_Handle_OpenWire_CH(5, Chip_Address); if ((OwOnChF & OUT6) != 0) System_Handle_OpenWire_CH(6, Chip_Address); if ((OwOnChF & OUT7) != 0) System_Handle_OpenWire_CH(7, Chip_Address); if ((OwOnChF & OUT8) != 0) System_Handle_OpenWire_CH(8, Chip_Address); if ((ShtVDDChF & OUT1) != 0) System_Handle_Short_to_VDD_CH(1, Chip_Address); if ((ShtVDDChF & OUT2) != 0) System_Handle_Short_to_VDD_CH(2, Chip_Address); if ((ShtVDDChF & OUT3) != 0) System_Handle_Short_to_VDD_CH(3, Chip_Address); if ((ShtVDDChF & OUT4) != 0) System_Handle_Short_to_VDD_CH(4, Chip_Address); if ((ShtVDDChF & OUT5) != 0) System_Handle_Short_to_VDD_CH(5, Chip_Address); if ((ShtVDDChF & OUT6) != 0) System_Handle_Short_to_VDD_CH(6, Chip_Address); if ((ShtVDDChF & OUT7) != 0) System_Handle_Short_to_VDD_CH(7, Chip_Address); if ((ShtVDDChF & OUT8) != 0) System_Handle_Short_to_VDD_CH(8, Chip_Address); } } uint8_t MAX14915_decode_channel_number(uint8_t CH_binary) { if ((CH_binary & OUT1) != 0) return 1; if ((CH_binary & OUT2) != 0) return 2; if ((CH_binary & OUT3) != 0) return 3; if ((CH_binary & OUT4) != 0) return 4; if ((CH_binary & OUT5) != 0) return 5; if ((CH_binary & OUT6) != 0) return 6; if ((CH_binary & OUT7) != 0) return 7; if ((CH_binary & OUT8) != 0) return 8; return 0; }
這些功能顯示了MAX14915的診斷特性。在此示例中,僅打印錯(cuò)誤條件。真正的應(yīng)用程序可能必須采取進(jìn)一步的操作:
void System_Handle_Overload_CH(uint8_t Channel, uint8_t Chip_Address) { // "Channel" is overloaded // System needs to handle over-load on "Channel" // Print to the User? // Just switch off? printf("MAX14915 %i - Channel %i is overloaded\r\n", Chip_Address, Channel); // Application actions MAX14915_read_register (Chip_Address, REG_OvlChF); // read to clear the flag // if error persists, the flag // will come back immediately } void System_Handle_Current_Limit_CH(uint8_t Channel, uint8_t Chip_Address) { // "Channel" is in current limiting mode // Does the system have to do anything in this case? // Print to the User? // Just switch off? printf("MAX14915 %i - Channel %i is in Current Limiting mode\r\n", Chip_Address, Channel); // Application actions MAX14915_read_register (Chip_Address, REG_CurrLimF); // read to clear the flag // if error persists, the flag // will come back immediately } void System_Handle_OpenWire_CH(uint8_t Channel, uint8_t Chip_Address) { // "Channel" is open wire // Does the system have to do anything in this case? // Print to the User? printf("MAX14915 %i - Channel %i is Open Wire\r\n", Chip_Address, Channel); // Application actions MAX14915_read_register (Chip_Address, REG_OwOnChF); MAX14915_read_register (Chip_Address, REG_OwOffChF); // read to clear the flag // if error persists, the flag // will come back immediately } void System_Handle_Short_to_VDD_CH(uint8_t Channel, uint8_t Chip_Address) { // "Channel" is shorted to VDD // Does the system have to do anything in this case? // Print to the User? // Just switch off? printf("MAX14915 %i - Channel %i is shorted to VDD\r\n", Chip_Address, Channel); // Application actions MAX14915_read_register (Chip_Address, REG_ShtVDDChF); // read to clear the flag // if error persists, the flag // will come back immediately } void System_Handle_Global_fault(uint8_t Chip_Address) { // read Global Error Register uint16_t global_error = MAX14915_read_register (Chip_Address, REG_GlobalErr); if ((global_error & 0x02) != 0) printf("MAX14915 %i Logic Undervoltage\r\n", Chip_Address); if ((global_error & 0x04) != 0) printf("MAX14915 %i VDD not good (below 16V)\r\n", Chip_Address); if ((global_error & 0x08) != 0) printf("MAX14915 %i VDD warning (below 13V)\r\n", Chip_Address); if ((global_error & 0x10) != 0) printf("MAX14915 %i VDD Undervoltage (below 8V)\r\n", Chip_Address); if ((global_error & 0x20) != 0) printf("MAX14915 %i Thermal Shutdown\r\n", Chip_Address); if ((global_error & 0x40) != 0) printf("MAX14915 %i SYNCH Error\r\n", Chip_Address); if ((global_error & 0x80) != 0) printf("MAX14915 %i Watchdog Error\r\n", Chip_Address); if ((global_error & 0x01) != 0) { // After a power-on reset all registers are in reset state // -> we need to re-initialize to our settings MAX14915_Init(Chip_Address); printf("MAX14915 %i Power-up Reset detected\r\n", Chip_Address); } } void System_Handle_CRC_Error(uint8_t Chip_Address) { // There was a CRC error printf("MAX14915 %i - CRC Error!\r\n", Chip_Address); // The Application needs to react here MAX14915_read_register (Chip_Address, REG_GlobalErr); // read to clear the flag // if error persists, the flag // will come back immediately }
結(jié)論
本應(yīng)用筆記介紹了如何對(duì)MAX14915進(jìn)行編程以驅(qū)動(dòng)輸出和診斷故障條件。該代碼使用MAX14915EVKIT進(jìn)行測(cè)試。工程師可以使用本應(yīng)用筆記中提到的C代碼示例,快速輕松地實(shí)現(xiàn)常用微控制器和MAX14915之間的接口。
審核編輯:郭婷
-
微控制器
+關(guān)注
關(guān)注
48文章
7552瀏覽量
151423 -
led
+關(guān)注
關(guān)注
242文章
23277瀏覽量
660873 -
SPI
+關(guān)注
關(guān)注
17文章
1706瀏覽量
91582
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論