I have a lot of pin_read function. How can i set all port one line? for example P1OUT = (P1.01 | P1.02 | P1.03) or P1IN = (P1.01 | P1.02 | P1.03) I dont know how to use pin mask?
here is my code and header file;
I have a lot of pin_read function. How can i set all port one line? for example P1OUT = (P1.01 | P1.02 | P1.03) or P1IN = (P1.01 | P1.02 | P1.03) I dont know how to use pin mask?
here is my code and header file;
#include <stdbool.h> #include <stdint.h> #include "boards.h" #include "nrf_delay.h" #include "nrf_gpio.h" #include "nrf.h" #include "nrf_drv_gpiote.h" #include "app_error.h" #include "nrf_drv_timer.h" #include "app_timer.h" #include "app_button.h" #include "nrf_drv_ppi.h" #include "nrf_drv_timer.h" #include "nrf_fstorage.h" #include "nordic_common.h" #include "ble.h" #include "ble_err.h" #include "ble_hci.h" #include "ble_srv_common.h" #include "ble_advdata.h" #include "ble_conn_params.h" #include "nrf_sdh.h" #include "nrf_sdh_ble.h" #include "ble_lbs.h" #include "nrf_ble_gatt.h" #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" #include "Tus_Tarama_Deneme.h" void Sutun_Cikislari(void) { nrf_gpio_cfg_output(LED_DENEME); nrf_gpio_cfg_output(SUTUN_1); nrf_gpio_cfg_output(SUTUN_2); nrf_gpio_cfg_output(SUTUN_3); nrf_gpio_pin_set(SUTUN_1); nrf_gpio_pin_set(SUTUN_2); nrf_gpio_pin_set(SUTUN_3); nrf_gpio_cfg_input(SATIR_1, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_1); nrf_gpio_cfg_input(SATIR_2, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_2); while(1) { if(nrf_gpio_pin_read(SATIR_1) || nrf_gpio_pin_read(SATIR_2)) { nrf_gpio_pin_set(LED_DENEME); } else { nrf_gpio_pin_clear(LED_DENEME); } } }
#define SUTUN_1 25 #define SUTUN_2 20 #define SUTUN_3 18 #define SATIR_1 16 #define SATIR_2 15 #define SATIR_3 14 #define SATIR_4 12 #define SATIR_5 10 #define LED_DENEME 24
Note that
if(nrf_gpio_pin_read(SATIR_1) || nrf_gpio_pin_read(SATIR_2))
is not completely identical to
if (NRF_GPIO->IN & ((1UL << SATIR_1) | (1UL << SATIR_2)))
because the code below only reads the IN register once.
One can set the output value of several pins using NRF_GPIO->OUT, but you can only set the mode of each pin individually, as each has its own mode register.
Hello everyone;
thanks for answerTurbo J I tried this and it worked. Then i changed someting in my code. But pins out it was not set high. I want to know where is my mistake?
unsigned char sutunlar; void Sutun_Cikislari(void) { nrf_gpio_cfg_output(LED_DENEME); sutunlar = NRF_GPIO->OUT & ((1UL << SUTUN_1) | (1UL << SUTUN_2) | (1UL << SUTUN_3)); // nrf_gpio_cfg_output(SUTUN_1); // nrf_gpio_cfg_output(SUTUN_2); // nrf_gpio_cfg_output(SUTUN_3); // nrf_gpio_pin_set(SUTUN_1); // nrf_gpio_pin_set(SUTUN_2); // nrf_gpio_pin_set(SUTUN_3); nrf_gpio_pin_set(sutunlar); nrf_gpio_cfg_input(SATIR_1, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_1); nrf_gpio_cfg_input(SATIR_2, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_2);
Hello everyone;
thanks for answerTurbo J I tried this and it worked. Then i changed someting in my code. But pins out it was not set high. I want to know where is my mistake?
unsigned char sutunlar; void Sutun_Cikislari(void) { nrf_gpio_cfg_output(LED_DENEME); sutunlar = NRF_GPIO->OUT & ((1UL << SUTUN_1) | (1UL << SUTUN_2) | (1UL << SUTUN_3)); // nrf_gpio_cfg_output(SUTUN_1); // nrf_gpio_cfg_output(SUTUN_2); // nrf_gpio_cfg_output(SUTUN_3); // nrf_gpio_pin_set(SUTUN_1); // nrf_gpio_pin_set(SUTUN_2); // nrf_gpio_pin_set(SUTUN_3); nrf_gpio_pin_set(sutunlar); nrf_gpio_cfg_input(SATIR_1, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_1); nrf_gpio_cfg_input(SATIR_2, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_2);
uint32_t sutunlar; void Sutun_Cikislari(void) { nrf_gpio_cfg_output(LED_DENEME); sutunlar = NRF_GPIO->OUT & ((1UL << SUTUN_1) | (1UL << SUTUN_2) | (1UL << SUTUN_3)); // nrf_gpio_cfg_output(SUTUN_1); // nrf_gpio_cfg_output(SUTUN_2); // nrf_gpio_cfg_output(SUTUN_3); // nrf_gpio_pin_set(SUTUN_1); // nrf_gpio_pin_set(SUTUN_2); // nrf_gpio_pin_set(SUTUN_3); nrf_gpio_pin_set(sutunlar); nrf_gpio_cfg_input(SATIR_1, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_1); nrf_gpio_cfg_input(SATIR_2, NRF_GPIOTE_POLARITY_LOTOHI); nrf_gpio_pin_read(SATIR_2); while(1) { if (NRF_GPIO->IN & ((1UL << SATIR_1) | (1UL << SATIR_2))) { nrf_gpio_pin_set(LED_DENEME); } else { nrf_gpio_pin_clear(LED_DENEME); } } }
here is my new code but it didn't happend.
this line is correct?
sutunlar = NRF_GPIO->OUT & ((1UL << SUTUN_1) | (1UL << SUTUN_2) | (1UL << SUTUN_3));