Tool/software:
Dear TI Team,
In our custom board, we are using the DS9092L+ IButton probe with the DS1971+F5 IButton interfaced with MSP432E4 Microcontroller. However, we are facing difficulties in reading the ROM code of the IButton.
Below are the connections for your reference:
- IButton Probe:
- Green (Data) connected to PORTE- E2 on the microcontroller
- Black (+ve LED) connected to PORTE- E3 on the microcontroller
- White (-ve LED) connected to GND
- Red (Ground) connected to GND
Additionally, we have connected a 4.7kohm resistor for pull-up on the data line.
I have also given below my microcontroller program for your reference.
#include <stdint.h>
// Definitions for PE2 and PE3
#define DQ_PIN BIT2
#define LED_PIN BIT3
#define DQ_PORT GPIOE
void delay_us(uint32_t us) {
// Delay function for microseconds (approximate)
uint32_t i;
for ( i = 0; i < (us * 3); i++) {
__NOP();
}
}
// 1-Wire reset function
void one_wire_reset() {
DQ_PORT->DIR |= DQ_PIN; // Set PE2 as output
DQ_PORT->DATA &= ~DQ_PIN; // Pull PE2 low
delay_us(480); // Delay 480 us
delayus(usecs);
DQ_PORT->DIR &= ~DQ_PIN; // Set PE2 as input
delay_us(70); // Delay 70 us
if (DQ_PORT->DATA & DQ_PIN) {
// No presence pulse detected
DQ_PORT->DATA &= ~LED_PIN; // Turn off LED
UARTprintf("No IButton detected.\n");
} else {
// Presence pulse detected
DQ_PORT->DATA |= LED_PIN; // Turn on LED
UARTprintf("IButton detected.\n");
}
delay_us(410); // Delay 410 us
}
// 1-Wire read bit function
uint8_t one_wire_read_bit() {
uint8_t bit = 0;
DQ_PORT->DIR |= DQ_PIN; // Set PE2 as output
DQ_PORT->DATA &= ~DQ_PIN; // Pull PE2 low
delay_us(6); // Delay 6 us
DQ_PORT->DIR &= ~DQ_PIN; // Set PE2 as input
delay_us(9); // Delay 9 us
bit = (DQ_PORT->DATA & DQ_PIN) ? 1 : 0; // Read bit
delay_us(55); // Delay 55 us
return bit;
}
// 1-Wire write bit function
void one_wire_write_bit(uint8_t bit) {
DQ_PORT->DIR |= DQ_PIN; // Set PE2 as output
DQ_PORT->DATA &= ~DQ_PIN; // Pull PE2 low
if (bit) {
delay_us(6); // Delay 6 us
DQ_PORT->DIR &= ~DQ_PIN; // Set PE2 as input
delay_us(64); // Delay 64 us
} else {
delay_us(60); // Delay 60 us
DQ_PORT->DIR &= ~DQ_PIN; // Set PE2 as input
delay_us(10); // Delay 10 us
}
}
// 1-Wire read byte function
uint8_t one_wire_read_byte() {
uint8_t i;
uint8_t byte = 0;
for (i = 0; i < 8; i++) {
byte |= (one_wire_read_bit() << i);
}
return byte;
}
// 1-Wire write byte function
void one_wire_write_byte(uint8_t byte) {
uint8_t i;
for ( i = 0; i < 8; i++) {
one_wire_write_bit(byte & (1 << i));
}
}
// Function to read the ROM code of the IButton
void read_rom(uint8_t *rom_code) {
uint8_t i;
one_wire_reset();
one_wire_write_byte(0x33); // Read ROM command
for ( i = 0; i < 8; i++) {
rom_code[i] = one_wire_read_byte();
UARTprintf("D[%d]:%x\n",i,rom_code[i]);
}
}
void main()
{
// Enable clock for Port E
SYSCTL->RCGCGPIO |= SYSCTL_RCGCGPIO_R4;
// Wait for Port E to be ready
while ((SYSCTL->PRGPIO & SYSCTL_PRGPIO_R4) == 0) {}
// Configure PE2 as bidirectional for 1-Wire (input/output)
DQ_PORT->DIR &= ~DQ_PIN; // Set PE2 as input initially
DQ_PORT->DEN |= DQ_PIN; // Enable digital function for PE2
// Configure PE3 as output for LED
DQ_PORT->DIR |= LED_PIN; // Set PE3 as output
DQ_PORT->DEN |= LED_PIN; // Enable digital function for PE3
read_rom(rom_code);
int i;
for (i=0;i<8;i++)
{
UARTprintf("D[%d]:%x\n",i,rom_code[i]);
}
// Main loop (could be used to continuously read data or handle other tasks)
while (1) {
// Your main application code
}
}
Kindly assist us in resolving this issue at your earliest convenience so that we can successfully read the ROM code of the IButton.
Thank you.