Uses the SAMD20 Xplained Pro as a slave I2C device in part 2 of the AT11628 app note, to the SAMD21 Xplained pro Master I2C device.
Refer to the SAMD21_Master_I2C First before building the SAMD20_Slave_I2C as many features carry over.
Starting with the Demo Board, ideally port to Userboard
- New GCC C ASF Board Project
- Choose SAMD20J18 -> Xplained Pro ATSAMD20J18 and verify LED Toggle with SW0 is working.
- Master will transmit a data buffer of a few bytes to the slave.
- Slave will re-transmit the same data buffer to the master.
- Using SERCOM2 (PA08 = SDA, PA09 = SCL). These I2C lines are available on all 3 EXT headers on the Xplained Pro board, can use any.
- SAMD20 Xplained pro has on-board 4.7k pullup resistors on I2C lines (R305, R306) (Left of PB02 on EXT1) which have been replaced with 2k pullup resistors to improve signal timing.
For the SAMD20J18A: worst case (Fast Mode) tr = 100ns, Cb = 400pF,
Master and slave application uses OSC8M as the clock source for Generator 0 (Undivided = 8MHz) fGCLK_SERCOM2_CORE (SERCOM2 input clock frequency) max = 48MHz
- Clock Init is the same as the MASTER code.
- pin_init and peripheral_function are the same as MASTER
One difference between the SAMD20 and the SAMD21 is that the SAMD21 supports Fast Mode I2C. SAMD20 supports Standard and Fast Mode frequencies (100khz and 400khz). SO we will have to make the SAMD21 match the SAMD20. The I2C standard Fm+ (Fast-mode plus) requires a nominal high to low SCL ratio of 1:2, and BAUD should be set accordingly. At a minimum, BAUD.BAUD and/or BAUD.BAUDLOW must be nonzero.
- i2c_slave_init: No SERCOM_I2CS_CTRLA_SPEED. Leave out.
- BAUD and BAUDLOW are left out.
- SYNCBUSY is undefined. Use: < while(SERCOM2->I2CS.STATUS.reg & SERCOM_I2CS_STATUS_SYNCBUSY); >
- Some of the SERCOM flags are allegedly read only.