makerdiary / base-dock

Grove compatible dock for building rapidly IoT applications with nRF52832-MDK or nRF52840-MDK
https://wiki.makerdiary.com/base-dock/
MIT License
4 stars 3 forks source link

Tutorial Request: <title> #2

Open Yug11 opened 5 years ago

Yug11 commented 5 years ago

Technical Level beginner I want to use the Grove - 4-Digit Display ( http://wiki.seeedstudio.com/Grove-4-Digit_Display/ )with nrf-52840 mdk using the base dock. I am not able to write the two-wire interface with respect to the mdk. Please help me with the nrf Compatible Display Library.

Yug11 commented 5 years ago

@caizelin Any reference material or help?

caizelin commented 5 years ago

@Yug11 Sorry for the late reply. Here is the library of Grove - 4-Digit Display: https://github.com/Seeed-Studio/Grove_4Digital_Display/ . You can port the APIs with nRF5 SDK. Just change digitalWrite and delayMicroseconds to nrf_gpio_pin_write and nrf_delay_us. I don't have a Grove-4-Digit Display in my hand, so you may port the library by yourself. Don't worry about getting your hands dirty! Just do it.

Yug11 commented 5 years ago

Thank you @caizelin, I am onto this. Just had a doubt that the library provided is given in c++, so do I also need to convert it into c in order to use it with nrf52840 mdk or the c++ library would work?

caizelin commented 5 years ago

Thank you @caizelin, I am onto this. Just had a doubt that the library provided is given in c++, so do I also need to convert it into c in order to use it with nrf52840 mdk or the c++ library would work?

Yes. You need to rewrite the APIs in C.

Yug11 commented 5 years ago

@caizelin I ported the cpp library to c library and changed the arduino functions to nrf gpio functions but still it doesnt work. Does this has to be done using the nrf twi?

Yug11 commented 5 years ago

here is the TM1637.h file

ifndef TM1637_h

define TM1637_h

include

include

bool _PointFlag;     //_PointFlag=1:the clock point on
void PinSet(uint8_t Clk, uint8_t Data);
void init(void);        //To clear the display
void writeByte(int8_t wr_data);//write 8bit data to tm1637
void start(void);//send start bits
void stop(void); //send stop bits
void display1(int8_t DispData[]);
void display(uint8_t BitAddr,int8_t DispData);
void clearDisplay(void);
void set(uint8_t brightness,uint8_t SetData,uint8_t SetAddr);//To take effect the next time it displays.
void point(bool PointFlag);//whether to light the clock point ":".To take effect the next time it displays.
void coding1(int8_t DispData[]); 
int8_t coding(int8_t DispData); 

endif

Yug11 commented 5 years ago

and the .c File

include "TM1637.h"

include "nrf_drv_gpiote.h"

include "nrf.h"

include "nrf_delay.h"

include

include

define ADDR_AUTO 0x40

define ADDR_FIXED 0x44

define STARTADDR 0xc0

define POINT_ON 1

define POINT_OFF 0

uint8_t Clkpin; uint8_t Datapin;

uint8_t Cmd_SetData; uint8_t Cmd_SetAddr; uint8_t Cmd_DispCtrl = 0;

static int8_t TubeTab[] = {0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71};//0~9,A,b,C,d,E,F

void PinSet(uint8_t Clk, uint8_t Data) { Clkpin = Clk; Datapin = Data; nrf_gpio_cfg_output(Clkpin); nrf_gpio_cfg_output(Datapin); }

void init(void) { clearDisplay(); }

void writeByte(int8_t wr_data) {

uint8_t i,count1=0;
for(i=0;i<8;i++) //sent 8bit data { nrf_gpio_pin_write(Clkpin,0);
if(wr_data & 0x01)nrf_gpio_pin_write(Datapin,1);//LSB first else nrf_gpio_pin_write(Datapin,0); wr_data >>= 1;
nrf_gpio_pin_write(Clkpin,1);

}
nrf_gpio_pin_write(Clkpin,0); //wait for the ACK nrf_gpio_pin_write(Datapin,1); nrf_gpio_pin_write(Clkpin,1);
nrf_gpio_cfg_input(Datapin,NRF_GPIO_PIN_NOPULL); while(nrf_gpio_pin_read(Datapin))
{ count1 +=1; if(count1 == 200)// { nrf_gpio_cfg_output(Datapin); nrf_gpio_pin_write(Datapin,0); count1 =0; } nrf_gpio_cfg_input(Datapin,NRF_GPIO_PIN_NOPULL); } nrf_gpio_cfg_output(Datapin);

} //send start signal to TM1637 void start(void) { nrf_gpio_pin_write(Clkpin,1);//send start signal to TM1637 nrf_gpio_pin_write(Datapin,1); nrf_gpio_pin_write(Datapin,0); nrf_gpio_pin_write(Clkpin,0); } //End of transmission void stop(void) { nrf_gpio_pin_write(Clkpin,0); nrf_gpio_pin_write(Datapin,0); nrf_gpio_pin_write(Clkpin,1); nrf_gpio_pin_write(Datapin,1); } //display function.Write to full-screen.

void display1(int8_t DispData[]) { int8_t SegData[4]; uint8_t i; for(i = 0;i < 4;i ++) { SegData[i] = DispData[i]; } coding1(&SegData[0]); start(); //start signal sent to TM1637 from MCU writeByte(ADDR_AUTO);// stop(); // start(); // writeByte(Cmd_SetAddr);// for(i=0;i < 4;i ++) { writeByte(SegData[i]); // } stop(); // start(); // writeByte(Cmd_DispCtrl);// stop(); // } //** void display(uint8_t BitAddr,int8_t DispData) { int8_t SegData; SegData = coding(DispData); start(); //start signal sent to TM1637 from MCU writeByte(ADDR_FIXED);// stop(); // start(); // writeByte(BitAddr|0xc0);// writeByte(SegData);// stop(); // start(); // writeByte(Cmd_DispCtrl);// stop(); // }

void clearDisplay(void) { display(0x00,0x7f); display(0x01,0x7f); display(0x02,0x7f); display(0x03,0x7f);
} //To take effect the next time it displays. void set(uint8_t brightness,uint8_t SetData,uint8_t SetAddr) { Cmd_SetData = SetData; Cmd_SetAddr = SetAddr; Cmd_DispCtrl = 0x88 + brightness;//Set the brightness and it takes effect the next time it displays. }

//Whether to light the clock point ":". //To take effect the next time it displays. void point(bool PointFlag) { _PointFlag = PointFlag; } void coding1(int8_t DispData[]) { uint8_t PointData; if(_PointFlag == POINT_ON)PointData = 0x80; else PointData = 0; for(uint8_t i = 0;i < 4;i ++) { if(DispData[i] == 0x7f)DispData[i] = 0x00; else DispData[i] = TubeTab[DispData[i]] + PointData; } } int8_t coding(int8_t DispData) { uint8_t PointData; if(_PointFlag == POINT_ON)PointData = 0x80; else PointData = 0; if(DispData == 0x7f) DispData = 0x00 + PointData;//The bit digital tube off else DispData = TubeTab[DispData] + PointData; return DispData; }

Yug11 commented 5 years ago

also the main file i've been using

include

include

include "boards.h"

include "app_util_platform.h"

include "app_error.h"

include "nrf_drv_twi.h"

include "nrf_delay.h"

include

include

include

include

include "bsp.h"

include "boards.h"

include "app_error.h"

include "nrf.h"

include "bsp.h"

include "nrf_delay.h"

include "nrf_drv_timer.h"

include "nrf_drv_gpiote.h"

include "nrf_drv_twi.h"

include "nrf_log.h"

include "nrf_log_ctrl.h"

include "nrf_log_default_backends.h"

include "TM1637.h"

define BRIGHT_DARKEST 0

define BRIGHT_TYPICAL 2

define BRIGHTEST 7

/**

}

/* @} /

Yug11 commented 5 years ago

@caizelin can you please help me with the TWI functions usage in nrf. As the display uses twi in the Arduino sketch and I guess nrf has a slightly different working of the twi.