Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example 1-Wire pin configuration #1048

Open
marcoramirezcastro opened this issue Jun 14, 2024 · 0 comments
Open

Example 1-Wire pin configuration #1048

marcoramirezcastro opened this issue Jun 14, 2024 · 0 comments

Comments

@marcoramirezcastro
Copy link

I compiled and ran the MAX32650FTHR example for 1-Wire communication and I was not able to see the 1-Wire line move.

The SDK provides the following function to configure and initialize the 1-Wire pin: MXC_OWM_Init(&owm_cfg);

Upon further examination I noticed that it calls the MXC_GPIO_Config(&gpio_cfg_owm) function passing the gpio_cfg_owm structure.

this structure configures the wrong settings for the MAX32650 device:

const mxc_gpio_cfg_t gpio_cfg_owm = { MXC_GPIO0, (MXC_GPIO_PIN_6 | MXC_GPIO_PIN_7), MXC_GPIO_FUNC_ALT2,
                                      MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };

as per the user guide the alternate function should be set to 1 instead of 2.
image

Other configuration may not be applied as well during setup using MXC_OWM_Init() such as the use of external pull up.

I fixed on my application by running 'MXC_OWM_Init()` first and sequentially reconfiguring the GPIO for the 1-Wire pin on the MAX32650FTHR.

A Working example:

#include <stdio.h>
#include "mxc_errors.h"
#include "owm.h"
#include "gpio.h"
#include "mxc_delay.h"

int main(void)
{
    int retval;
    
    printf("***** 1-Wire Reset Pulse Test *****\n");
    printf("This example sends a reset pulse and checks for a presence response\n");
    printf("Connect 1-Wire pin, VCC, and GND to the target\n");
    printf("\n\n");

    // Initialize the OWM configuration structure
    mxc_owm_cfg_t owm_cfg;
    owm_cfg.int_pu_en = 1; // Enable internal pull-up
    owm_cfg.ext_pu_mode = MXC_OWM_EXT_PU_UNUSED; // Ensure external pull-up is off
    owm_cfg.long_line_mode = 0;





    // Initialize the OWM module with the specified configuration
    MXC_OWM_Init(&owm_cfg);

    // Configure GPIO for 1-Wire
    mxc_gpio_cfg_t gpio_cfg = {
        .port = MXC_GPIO1,
        .mask = (MXC_GPIO_PIN_31),
        .pad = MXC_GPIO_PAD_STRONG_PULL_UP, // Set pad to pull-up
        .func = MXC_GPIO_FUNC_ALT1,
        .vssel = MXC_GPIO_VSSEL_VDDIOH,
        .drvstr = MXC_GPIO_DRVSTR_3
    };
    MXC_GPIO_Config(&gpio_cfg);


    // Send a reset pulse and check for a presence response
    MXC_Delay(MXC_DELAY_SEC(5));
    retval = MXC_OWM_Reset();

    if (retval == 0) {
        printf("No presence pulse detected. No device is present on the bus.\n");
        
    } else if (retval == 1) {
        printf("Presence pulse detected. Device is present on the bus.\n");
    } else {
        printf("Error during reset pulse. Error code: %d\n", retval);
    }

    // Deinitialize the OWM module
    MXC_OWM_Shutdown();

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant