MikroSDK Port Read function problem

Fully featured PIC compilers available on Windows, Linux, and macOS.
Post Reply
Author
Message
wuu
Posts: 115
Joined: 24 Mar 2008 00:48

MikroSDK Port Read function problem

#1 Post by wuu » 06 Sep 2021 20:36

Hi,

I'm trying to use the Necto and MikroSDK for a new project, but I have problems even with simple tasks. I'm trying to use port driver but it's not working.
my implementation is looking like this but it always reads 0. However, Writing to port works ok. What could be the problem?

Code: Select all

#include "drv_uart.h"
#include "drv_port.h"
#include "conversions.h"
#include "board.h"

#ifndef PORT_B
#define PORT_B NC
#endif

#ifndef PORT_D
#define PORT_D NC
#endif

// Port driver context structure.
static port_t portb;
static port_t portd;

//Port value
static uint16_t read_value;

void application_init ( void )
{
     uint16_t mask  = 0xFFFF;
     
    // Initialize PORT_D as output.
    port_init( &portd, PORT_D, mask, PIN_DIRECTION_DIGITAL_INPUT );
}
void application_task ( void )
{
    // Read port and toggle value.
    read_value = port_read( &portd );  
}
void main()
{
    application_init();
    while( 1 )
    {                
        application_task();
    }
}
I'm using PIC18F45K22 on EasyPIC v7. What am I missing?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: MikroSDK Port Read function problem

#2 Post by filip » 07 Sep 2021 14:21

Hi,

Can you please attach detailed photo of the development board ?

Regards,
Filip.

wuu
Posts: 115
Joined: 24 Mar 2008 00:48

Re: MikroSDK Port Read function problem

#3 Post by wuu » 07 Sep 2021 15:02

Hi Filip,

not exactly sure what do you mean? Picture of physical board or picture of configuration?
A picture of the configuration can be attached, Otherwise, the physical configuration is EasyPIC v7. I can take a picture of it when I come home if you need it.


Best regards, Miha
Attachments
EasyPIC v7 configuration.png
EasyPIC v7 configuration.png (344.8 KiB) Viewed 1862 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: MikroSDK Port Read function problem

#4 Post by filip » 08 Sep 2021 10:27

Hi,

Yes, the photo of the EasyPIC v7 development board.

Regards,
Filip.

wuu
Posts: 115
Joined: 24 Mar 2008 00:48

Re: MikroSDK Port Read function problem

#5 Post by wuu » 08 Sep 2021 11:53

Hi Filip,

please find attached a picture of the EasyPIC v7:
Attachments
20210908_124044.jpg
20210908_124044.jpg (1.76 MiB) Viewed 1856 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: MikroSDK Port Read function problem

#6 Post by filip » 17 Sep 2021 15:33

Hi,

Please pull-down PORT and put button press level to VCC, see if this works now.

Regards,
Filip.

wuu
Posts: 115
Joined: 24 Mar 2008 00:48

Re: MikroSDK Port Read function problem

#7 Post by wuu » 17 Sep 2021 19:38

Hi Filip,

I had tested this code and it does not work:

Code: Select all

// ------------------------------------------------------------------ INCLUDES
#include "drv_port.h"

// If hardware without port C is used, make sure to define adequate port.
#ifndef PORT_B
#define PORT_B NC
#endif
#ifndef PORT_C
#define PORT_C NC
#endif

// ------------------------------------------------------------------ VARIABLES
static port_t port_b;     // Port driver context structure.
static port_t port_c;     // Port driver context structure.

// ------------------------------------------------------------------ USER CODE
void main()
{
    uint16_t mask  = 0xFFFF;
    uint16_t value = 0x5555;

    // Initialize PORT_C as output.
    port_init( &port_b, PORT_B, mask, PIN_DIRECTION_DIGITAL_INPUT );
    port_init( &port_c, PORT_C, mask, PIN_DIRECTION_DIGITAL_OUTPUT );

    // Read port and toggle value.
    value = port_read( &port_b );
    
    // Write value to GPIO port.
    port_write( &port_c, value );    

}
Attachments
20210917_203556.jpg
20210917_203556.jpg (1.43 MiB) Viewed 1826 times

Post Reply

Return to “PIC AI compilers”