I have been trying to get a 18F2620 to run as a slave. i ran across this in the ERRATA for this device.
I have gotten sporadic results for the master reading the slave in the following code.Code:43. Module: MSSP (I2C Slave) The MSSP module operating in I2C, 7-Bit Slave mode (SSPM3:SSPM0 = 0110) may not send a NACK bit (/ACK) in response to receiving the slave address loaded in SSPADD<7:1>. Addresses are in one of these ranges: 0x00 to 0x07 0x78 to 0x7F These addresses were reserved by Philips® Semiconductors in The I2C Specification, Version 2.1, released January 2000. Section 10.1 Definition of bits in the first byte defines the purposes of these addresses. This specification can be found at: http://www.semiconductors.philips.com/i2c Work around This version of the silicon does not respond to slave addresses in the ranges previously listed. Use either of these work arounds: Change the 7-bit slave address in SSPADD to an address in the range of 0x08 to 0x77. Use Revision B silicon. This version of silicon removes this issues addressing restrictions.
Darrell's Instant Interrupt
The Interrupt handlerCode:' Interrupt definition ' ==================== ' USB interrupt used to keep USB connection alive INCLUDE "DT_INTS-18.bas" ' Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler SSP_INT, _I2C_Int, PBP, yes endm INT_CREATE ; Creates the interrupt processor endasm ''----------------- Initialization Done! ----------------------------- @ INT_ENABLE SSP_INT ; Master Synchronous Serial Port Interrupt Flag bit. The transmission/reception is complete 'txbuffer = 0
and the main loop. I want to send three bytes to the master. In this case "three sevens".Code:I2C_Int: If R_W = 0 then if D_A = 0 then address = SSPBUF else Still working on master to slave write ' if bf = 1 then ' if rxcnt <= rxbufferlen then ' datain[rxcnt] = SSPBUF ' rxcnt = rxcnt + 1 ' if rxcnt = rxbufferlen then rxcnt = 0 ' endif EndIF endif else dataout = SSPBUF 'dummy read if txcnt > 0 then SSPBUF = txbuffer[txoutptr] txoutptr = txoutptr + 1 if txoutptr = txbufferlen then txoutptr = 0 txcnt = txcnt - 1 else 'no byte to send endif endif CKP = 1 @ INT_RETURN
I did the same slave program in "C" and it works well.Code:Main: SSPOV = 0 WCOL = 0 if txcnt < txbufferlen - 1 then TxBuffer[txinptr] = 7 txinptr = txinptr + 1 if txinptr = txbufferlen then txinptr = 0 txcnt = txcnt + 1 endif WrData=0 goto main end
The Master is reading and writing to a RTC module and a bank of 4 24lc256 EEProms and a I2C Port expander with out any problems.
It is getting close
Take care
Dave




Bookmarks