Open Yug11 opened 5 years ago
@caizelin Any reference material or help?
@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.
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?
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.
@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?
here is the TM1637.h file
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);
and the .c File
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; }
also the main file i've been using
/**
@brief Function for main application entry. */ int main(void) {
PinSet(27,26); init(); set(7,0x40,0xc0); //uint8_t SetData = ; //uint8_t SetAddr = ; int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F int8_t ListDisp[4]; unsigned char i = 0; unsigned char count = 0; nrf_delay_ms(150);
//nrf_delay_ms(150);
APP_ERROR_CHECK(NRF_LOG_INIT(NULL)); NRF_LOG_DEFAULT_BACKENDS_INIT(); NRF_LOG_INFO("\r\nTWI sensor example started."); NRF_LOG_FLUSH();
while(1) { i = count; count ++; if(count == sizeof(NumTab)) count = 0; for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++) { ListDisp[BitSelect] = NumTab[i]; i ++; if(i == sizeof(NumTab)) i = 0; } display(0,ListDisp[0]); display(1,ListDisp[1]); display(2,ListDisp[2]); display(3,ListDisp[3]); nrf_delay_ms(300); }
NRF_LOG_INFO("\r\nstill running ."); NRF_LOG_FLUSH();
}
/* @} /
@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.
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.