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

Commision Short Adress #1

Open
kemaldede opened this issue Jul 4, 2019 · 2 comments
Open

Commision Short Adress #1

kemaldede opened this issue Jul 4, 2019 · 2 comments

Comments

@kemaldede
Copy link

Hi. I can't commision the ballasts. Here is my code. I reconfigured the rst and int pins.
RST pin : C3
INT pin : A10

`#include "Click_DALI_2_types.h"
#include "Click_DALI_2_config.h"
#include "Click_DALI_2_timer.h"
#include "stdbool.h"
#include "stdint.h"

uint8_t current_state;
uint8_t numberOfBallasts = 0;
uint8_t counter;
char int_to_str[7];
char long_to_str[12];

uint32_t findDev(uint32_t base_addr, uint32_t pattern_addr, uint8_t shift_counter);
void setSearch(uint32_t addr);

void systemInit()
{
mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_INT_PIN, _GPIO_OUTPUT );
mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_RST_PIN, _GPIO_OUTPUT );

UART2_Init_Advanced(115200, _UART_8_BIT_DATA, _UART_NOPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART2_PA23);

}

void applicationInit()
{
dali2_gpioDriverInit( (T_DALI2_P)&_MIKROBUS1_GPIO );
dali2_masterInit();
dali2_configTimer();
}

void applicationTask()
{
for (counter = 0; counter < 2; counter++)
{
dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_OFF, _DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);
Delay_ms( 1000 );
dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_RECALL_MAX_LEVEL, _DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);
Delay_ms( 1000 );
}

for (counter = 0; counter < 8; counter++)
{
    dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_DOWN, _DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);
    Delay_ms( 500 );
}

for (counter = 0; counter < 8; counter++)
{
    dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_UP, _DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);
    Delay_ms( 500 );
}

}

uint8_t setDevAddress(uint8_t start_addr){

uint32_t addr_dev = 0xFF;

// UART2_Write_Text("Arama islemi basliyor....");
dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_RESET, _DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);
Delay_ms( 100 );
dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_RESET, _DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND); // Balastlar resetleniyor
Delay_ms(100);
dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_OFF, _DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND); // Lambaları söndür
Delay_ms( 300 );

dali2_sendCmd(_DALI2_ADDRESS01,_DALI2_INITIALISE,_DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);   // Initialize komutu
Delay_ms(100);
dali2_sendCmd(_DALI2_ADDRESS01,_DALI2_INITIALISE,_DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);
Delay_ms(100);
dali2_sendCmd(_DALI2_RANDOMISE_L,_DALI2_RANDOMISE_H,_DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);     // Ramdomize komutu
Delay_ms(100);
dali2_sendCmd(_DALI2_RANDOMISE_L,_DALI2_RANDOMISE_H,_DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);
Delay_ms(100);

while(1){
    addr_dev = findDev(0xFFFFFF, 0x800000,0);
                    
    if (addr_dev == 0xFFFFFFFF)       //Adreslemeden çıkılıyor
        break;
        
    UART2_Write_Text("Device Found!!!!");
    UART2_Write(13);
    UART2_Write(10);
    setSearch(addr_dev);   // Search komutu ile
    dali2_sendCmd(((start_addr << 1) | 0x01),_DALI2_PROGRAM_SHORT_ADDRESS, _DALI2_COMMAND,_DALI2_FOLLOWING_COMMAND); // Kısa adres programlandı
    Delay_ms(100);
    dali2_sendCmd(_DALI2_WITHDRAW_L, _DALI2_WITHDRAW_H, _DALI2_COMMAND,_DALI2_FOLLOWING_COMMAND);   // Kısa adresi atanan ballast arama döngüsünden çıkarılıyor
    Delay_ms(100);
    start_addr++;
    numberOfBallasts++;
}
dali2_sendCmd(_DALI2_TERMINATE_L_BITS, _DALI2_TERMINATE_H_BITS, _DALI2_BROADCAST_CMD,_DALI2_FOLLOWING_COMMAND);   // Terminate komutu
return start_addr;

}

uint32_t findDev(uint32_t base_addr, uint32_t pattern_addr, uint8_t shift_counter){

uint8_t ballast_response;

setSearch(base_addr);
dali2_sendCmd(_DALI2_COMPARE_L,_DALI2_COMPARE_H,_DALI2_BROADCAST_CMD, _DALI2_FOLLOWING_COMMAND);       // Compare komutu
Delay_ms(10);
ballast_response = dali2_getBallastResponse();

if(ballast_response){
    if (shift_counter == 24)
        return base_addr;
    else
        base_addr -= pattern_addr;
} 
else {
    if (shift_counter == 0){
        UART2_Write_Text("Device Not Found!!!");
        UART2_Write(13);
        UART2_Write(10);
        return 0xFFFFFFFF;
    }
    else if (shift_counter > 23){
        return (base_addr + 1);
    }
    else{
        base_addr += pattern_addr;
    }
        
}

if (shift_counter != 23){
    pattern_addr >>= 1;
}
            
shift_counter++;

base_addr = findDev(base_addr, pattern_addr, shift_counter);
return base_addr;

}

void setSearch(uint32_t addr){

 uint8_t searchAdrrH,searchAdrrM,searchAdrrL;
 char long_to_hex[9];
 searchAdrrH = ((addr >> 16) & 0xFF);
 searchAdrrM = ((addr >> 8) & 0xFF);
 searchAdrrL = (addr & 0xFF);
 
 LongIntToHex(addr,long_to_hex);
 UART2_Write_Text(long_to_hex);
 UART2_Write(13);
 UART2_Write(10);
 
 dali2_sendCmd(searchAdrrH,_DALI2_SEARCHADDRH,_DALI2_COMMAND, _DALI2_FOLLOWING_COMMAND);
 Delay_ms(30);
 dali2_sendCmd(searchAdrrM,_DALI2_SEARCHADDRM,_DALI2_COMMAND, _DALI2_FOLLOWING_COMMAND);
 Delay_ms(30);
 dali2_sendCmd(searchAdrrL,_DALI2_SEARCHADDRL,_DALI2_COMMAND, _DALI2_FOLLOWING_COMMAND);
 Delay_ms(30);

}

void main()
{
uint8_t n_dev = 0;
systemInit();
applicationInit();
applicationTask();
n_dev = setDevAddress(0x00);

    while(1){
    
        dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_RECALL_MAX_LEVEL, _DALI2_COMMAND, _DALI2_FOLLOWING_COMMAND);
        Delay_ms( 1000 );

        for (counter = 0; counter < 8; counter++)
        {
            dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_DOWN, _DALI2_COMMAND, _DALI2_FOLLOWING_COMMAND);
            Delay_ms( 500 );
        }

        for (counter = 0; counter < 8; counter++)
        {
            dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_UP, _DALI2_COMMAND, _DALI2_FOLLOWING_COMMAND);
            Delay_ms( 500 );
        }
        
        dali2_sendCmd(_DALI2_ADDRESS01, _DALI2_OFF, _DALI2_COMMAND, _DALI2_FOLLOWING_COMMAND);
        Delay_ms( 1000 );
        
    }

}`

@busy-reiding
Copy link

busy-reiding commented Sep 6, 2019

Hi there, I was wondering if you were able to figure this out? I’m having some trouble with it too.

@kemaldede
Copy link
Author

Unfortunately, I can't. Seems no one give us some help from mikroe team

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

2 participants