use mikrobus library whithout mikrobus

General discussion on Libstock website & codes posted on this website.
Post Reply
Author
Message
petrus88
Posts: 30
Joined: 24 Oct 2019 12:10

use mikrobus library whithout mikrobus

#1 Post by petrus88 » 24 Oct 2019 13:07

Hello to all,

i have would to use in a my project a board like flash2 clik.
I see for this click board there are a library in libstock release for a mikrobus system, bu i would to use this board whidout mikrobus system, with a diferte spi bus or a different pin.

It si possible? or i have to write my personal library?

Thank a lot
p

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: use mikrobus library whithout mikrobus

#2 Post by stefan.filipovic » 25 Oct 2019 14:43

Hi,

You would need to write your own board definition files or to adjust the present ones.
Please refer to the following link:
https://www.mikroe.com/blog/mikrosdk-bo ... tion-files

Kind regards,
Stefan Filipović

Richie800
Posts: 50
Joined: 09 Jul 2007 00:31

Re: use mikrobus library whithout mikrobus

#3 Post by Richie800 » 16 May 2020 12:51

You would need to write your own board definition files or to adjust the present ones.
Please refer to the following link:
https://www.mikroe.com/blog/mikrosdk-bo ... tion-files
The real question here is “what do I get out of this”. The answer is: by following the mikroSDK standard you get immediately usable click board application code for every mikroBUS™ compliant click board™, independent on the used development platform.
How would you recommend someone begin this process? The main focus of the SDK standard is to create language that can be used across platforms. However, how can a beginner read and understand what is going on and use that to create their own code?

I have been looking at these different Click boards and it is a bit difficult for me to follow. The following code does not even compile without any modification. Also, unlike the second example of code, there are not comments to tell me what each line of code does. So I am left guessing or at least looking for support documents to understand whats happening.

I have not been monitoring the forum for some time but the biggest reason I purchased the development board and the compiler was because I could develop my own code based on the original code. I am not suggesting that this is no longer the case. I am saying it is a little more difficult (or at least different) to follow the code only ( and the data sheet). I was able to write a CANbus bootloader based on CAN and Bootloader examples. If I wanted to use CAN FD4 on my own board without the click pinout, where would I begin?

Is Libstick codes ( really MikroSDK) written closer to C language than Basic? I have read the information on MikroSDK but even that uses C as examples to explain the architecture. Are you moving away from Basic?

Code: Select all

program Click_CANFD4_PIC

include Click_CANFD4_types
include Click_CANFD4_config
dim
    APP_MODE_RECEIVER as uint8_t 
    APP_MODE_TRANSMITER as uint8_t 
    app_mode as uint8_t 
    demo_message_data as uint8_t[9] 
    
sub procedure system_init() 
    mikrobus_gpioInit(_MIKROBUS2, _MIKROBUS_CS_PIN, _GPIO_OUTPUT)
    mikrobus_uartInit(_MIKROBUS2, @CANFD4_UART_CFG[0])
    mikrobus_logInit(_LOG_USBUART, 9600) 
    Delay_ms(100) 
end sub

sub procedure application_init() 
    canfd4_uart_driver_init(canfd4_obj_t(@_MIKROBUS1_GPIO), canfd4_obj_t(@_MIKROBUS1_UART)) 
    mikrobus_logWrite("---- Initialized ----", _LOG_LINE) 
    canfd4_set_dev_mode(CANFD4_NORMAL_MODE) 
    app_mode = APP_MODE_TRANSMITER 
    Delay_ms(100) 
end sub

sub procedure application_task() 
dim
    tmp as char 
    drdy_flag as uint8_t 

    if (app_mode = APP_MODE_RECEIVER) then 
        drdy_flag = canfd4_byte_ready() 
        if (1 = drdy_flag) then 
            tmp = canfd4_read_byte() 
            mikrobus_logWrite(@tmp, _LOG_BYTE) 
        end if
    else 
        for tmp = 0 to 9 - 1 
            canfd4_write_byte(demo_message_data[tmp]) 
            mikrobus_logWrite(">> MESSAGE SENT <<", _LOG_LINE) 
        next tmp
        Delay_ms(2000) 
    end if
end sub

main :
    APP_MODE_RECEIVER = 1
    APP_MODE_TRANSMITER = 0
    demo_message_data[0] = "M"
    demo_message_data[1] = "i"
    demo_message_data[2] = "k"
    demo_message_data[3] = "r"
    demo_message_data[4] = "o"
    demo_message_data[5] = "E"
    demo_message_data[6] = 13
    demo_message_data[7] = 10
    demo_message_data[8] = 0

    system_init() 
    application_init() 
    while (1) 
        application_task() 
    wend
end.

Code: Select all

program Can_Spi_1st

dim Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags as byte   ' can flags
    Rx_Data_Len as byte                                     ' received data length in bytes
    RxTx_Data   as byte[8]                                  ' can rx/tx data buffer
    Msg_Rcvd as byte                                        ' reception flag
    Tx_ID, Rx_ID as longint                                 ' can rx and tx ID

' CANSPI module connections
dim CanSpi_CS as sbit at RC0_bit
    CanSpi_CS_Direction as sbit at TRISC0_bit
    CanSpi_Rst as sbit at RC2_bit
    CanSpi_Rst_Direction as sbit at TRISC2_bit
' End CANSPI module connections

main:
  ANSEL  = 0                       ' Configure AN pins as digital I/O
  ANSELH = 0
  PORTB = 0
  TRISB = 0

  Can_Init_Flags = 0                                      '
  Can_Send_Flags = 0                                      ' clear flags
  Can_Rcv_Flags  = 0                                      '

  Can_Send_Flags = _CANSPI_TX_PRIORITY_0 and              ' form value to be used
                    _CANSPI_TX_XTD_FRAME and              '     with CANSPIWrite
                    _CANSPI_TX_NO_RTR_FRAME

  Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE and       ' form value to be used
                    _CANSPI_CONFIG_PHSEG2_PRG_ON and      ' with CANSPIInit
                    _CANSPI_CONFIG_XTD_MSG and
                    _CANSPI_CONFIG_DBL_BUFFER_ON and
                    _CANSPI_CONFIG_VALID_XTD_MSG

  SPI1_Init()                                                      ' initialize SPI1 module
  CANSPIInitialize(1,3,3,3,1,Can_Init_Flags)                       ' Initialize external CANSPI module
  CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF)                 ' set CONFIGURATION mode
  CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG)         ' set all mask1 bits to ones
  CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG)         ' set all mask2 bits to ones
  CANSPISetFilter(_CANSPI_FILTER_B2_F4,3,_CANSPI_CONFIG_XTD_MSG)   ' set id of filter B1_F1 to 3

  CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF)                 ' set NORMAL mode

  RxTx_Data[0] = 9                                                 ' set initial data to be sent

  Tx_ID = 12111                                                    ' set transmit ID

  CANSPIWrite(Tx_ID, RxTx_Data, 1, Can_Send_Flags)                 ' send initial message
  while TRUE                                                       ' endless loop
    Msg_Rcvd = CANSPIRead(Rx_ID , RxTx_Data , Rx_Data_Len, Can_Rcv_Flags)   ' receive message
    if ((Rx_ID = 3) and Msg_Rcvd) then                                      ' if message received check id
      PORTB = RxTx_Data[0]                                                  ' id correct, output data at PORTC
      Inc(RxTx_Data[0])                                                     ' increment received data
      Delay_ms(10)
      CANSPIWrite(Tx_ID, RxTx_Data, 1, Can_Send_Flags)                      ' send incremented data back
    end if
  wend
end.
I added the this post because I believe it follows the same line of questioning or falls within the intention of the original post. If this is not the case, I apologize.

Rich

Post Reply

Return to “Libstock Discussion”