|
Broken 5V supply to LCD!
I should have know better since the LCD did not react to power-up - reset and show 5/7 characters - but the power LED was on on the i2c module itself !
Learned few Linux tools on how to troubleshoot i2c, so no big loss.
Now I can proceed with implementing ioctl.
I would like to discuss implementation of Linux ioctl function.
There are few reasons I am posting my question here and not on Linux forum. However, if you feel it is inappropriate you have two options - ignore my request ( preferred to sermon ) or flag it to be removed.
I am basically aware WHAT ioctl does, and have been thru few documents ( Linux Device drivers, CodeProject driver tutorials etc.)
I am trying to implement ioctl "driver" to output (Raspberry Pi) to I2C LCD.
The problems I cannot get straight is how to configure I2C speed (using C++, not Linux commands ) and implement ACK read from slave I2C device.
I understand I2C protocol, but all of the sample codes I have read so far are "limited" to open ioctl file and "write " to I2C slave address.
I like to see or make my own code to implement I2C "start /stop " and read ACK/ NACK from slave.
Any to the point help will as always be appreciated.
Thanks
-- modified 7-Apr-18 15:35pm.
|
|
|
|
|
You have two options:
- Use the existing I2C support on the Raspberry Pi with the I2C GPIO pins
- Implement your own I2C support on general use GPIO pins
The I2C speed is defined by the master by generating the clock. A device might use "clock stretching" to slow down (Clock, Stretching, Arbitration - I2C Bus[^]).
So implementations are not time critical. They can use a predefined (max.) clock and have not to care about being slowed down by other tasks on the system.
I have implemented I2C in assembler on micro controllers. Implementing it in C is not a problem but be aware that it might be a frustrating tasks because it can't be simply debugged. I highly recommend to use a logic analyser or at least a storage oscilloscope to check the signals on the bus.
Quote: all of the sample codes I have read so far are "limited" to open ioctl file and "write " to I2C slave address. With device drivers use i2c_transfer() . Have a look at the source of any Linux driver for a I2C device like rtc-pcf8563.c
[^].
When using ioctl() on the I2C device just use read() :
int fd = open("/dev/i2c-1", O_RDWR);
ioctl(fd, I2C_SLAVE, addr);
read(fd, buffer, length); Or use ioctl(I2C_RDWR) or ioctl(I2C_SMBUS) for reading which both does not require the I2C_SLAVE[_FORCE] . In any case check first if the used ioctl() call is supported.
|
|
|
|
|
The speed is configured outside the program or on the library you are using on the Pi
Edit /boot/config.txt if it doesn't exist create it
add the line or edit the line with your baudrate
dtoverlay=i2c-speed,i2c1_baudrate=400000
i2c1 may also be disabled by default I can't remember if so you need
dtparam=i2c_vc=on
In the userland repository there is also a direct header and library
bcm2835: C library for Broadcom BCM 2835 as used in Raspberry Pi[^]
and a forum
bcm2835 : Google Groups[^]
Standard use
#include <bcm2835.h>
int main(int argc, char **argv)
{
char buf[1];
if (!bcm2835_init())return 1;
bcm2835_i2c_begin();
bcm2835_i2c_setSlaveAddress(0x20);
bcm2835_i2c_set_baudrate(10000);
while(1)
{
buf[0] = 0xEF;
bcm2835_i2c_write(buf,1);
bcm2835_delay(500);
buf[0] = 0xFF;
bcm2835_i2c_write(buf,1);
bcm2835_delay(500);
}
bcm2835_i2c_end();
bcm2835_close();
return 0;
}
In vino veritas
modified 26-Mar-18 23:06pm.
|
|
|
|
|
Thanks for replies.
I am currently "on the road" and will reply when I get home.
In short
I did try "just GPIO" , it worked to the point, but it got too convoluted.
Hence I am after using ioctl.
I'll take a look at the bcm2835.h, hopefully I can use it for bcm2837 chip used in RPi 3B.
I think my main concern is still to be able to "see" the code following / running the I2C spec - mainly changing hardware pins directions and reading START /STOP and ACK/NACK back. Of course I am verifying the actual LCD and sometime even using scope.
Thanks for all your comments, appreciate that.
-- modified 5-Apr-18 12:42pm.
|
|
|
|
|
I converted VS2008 solution (sln) to VS2017. Visual Studio is up-to-date - version 15.6.4.
My solution contains tens of C++ projects - executables, dll's and lib's. Now I have a weird issue - dll's cannot be debugged in Debug configuration.
In Release configuration it works - breakpoints can be used.
But in Debug configuration all the breakpoints are disabled and there is a hint - "The breakpoint will not currently be hit. No symbols have been loaded for this document."
When I try to load symbols (pdb) manually I'm getting a message "A matching symbol file was not found in this folder."
In DLL project settings (vcxproj file) GenerateDebugInformation is true.
I'm a bit confused why generated pdb file cannot be used by Visual Studio.
|
|
|
|
|
The chances are that your DLL needs to be rebuilt.
|
|
|
|
|
Have you converted the solution in-place (with existing output files from old VS 2008 builds)?
Then try to delete all output files (especially old ones which can be identified by the time stamp).
|
|
|
|
|
Hi,
The 'Debug' build is just a text label... in other words it sounds like your DLL is being compiled with the symbols stripped out. There is nothing stopping someone from configuring 'Debug' exactly as a 'Release' build.
Try using DUMPBIN /SYMBOLS[^] on your DLL to check if the symbol tables exists.
Don't forget that you can PIPE the output into a text file:
DUMPBIN /SYMBOLS YourDLL.DLL > symbols.txt
Best Wishes,
-David Delaune
|
|
|
|
|
Hello Everybody,
I am using VC++ and OpenGL for one application.
I am new to OpenGL. I can able to load different objects and also able to create vertices. After that, I was able to select and pick those using glReadPixels and gluUnProject.
Now, I need to select and pick lines (edges of the triangles). I searched in google and not able to find a proper result.
Can anybody give me ideas how to implement this?
Thanks in Advance.
Regards,
Gopi.
|
|
|
|
|
Find the line in your list that is closest the point or at least less than some tolerance value
A number of Contributed implementations of the formula here plus an explaination of the mathematics
Point, Line, Plane[^]
Implementation would look something like this
#define GLfloat float // No sure if you want floats or double you can change here
GLfloat GLDistance2D (GLfloat x1, GLfloat y1,
GLfloat x2, GLfloat y2)
{
GLfloat dx, dy;
dx = x2 - x1;
dy = y2 - y1;
if ( dx < -FLT_EPSILON || dx > FLT_EPSILON ||
dy < -FLT_EPSILON || dy > FLT_EPSILON )
{
return sqrtf(dx * dx + dy * dy);
}
return (GLfloat) 0.0;
}
GLfloat GLDistanceToLine2D (GLfloat px, GLfloat py,
GLfloat x1, GLfloat y1,
GLfloat x2, GLfloat y2,
bool linesegment,
GLfloat* cpx, GLfloat* cpy)
{
GLfloat u;
GLfloat dx = x2 - x1;
GLfloat dy = y2 - y1;
GLfloat SqLineMag = dx * dx + dy * dy;
if (SqLineMag > -FLT_EPSILON && SqLineMag < FLT_EPSILON) {
if (linesegment) return GLDistance2D(px, py, x1, y1);
else return (GLfloat)-1.0;
}
u = ((px - x1)* dx + (py - y1)* dy) / SqLineMag;
if ((linesegment) && ((u < FLT_EPSILON) || (u > (GLfloat)1.0)))
{
GLfloat ix, iy;
ix = GLDistance2D(px, py, x1, y1);
iy = GLDistance2D(px, py, x2, y2);
if (ix < iy) {
if (cpx) (*cpx) = x1;
if (cpy) (*cpy) = y1;
return(ix);
}
else {
if (cpx) (*cpx) = x2;
if (cpy) (*cpy) = y2;
return(iy);
}
}
else {
GLfloat ix, iy;
ix = x1 + (u * dx);
if (cpx) (*cpx) = ix;
iy = y1 + (u * dy);
if (cpy) (*cpy) = iy;
return GLDistance2D(px, py, ix, iy);
}
}
Run a test .. it should return ix,iy = (200,100) dist = 100 ... plot it you will see why.
GLfloat ix, iy;
GLfloat dist = GLDistanceToLine2D(100, 100, 200, 0, 200, 200, true, &ix, &iy);
In vino veritas
modified 23-Mar-18 2:36am.
|
|
|
|
|
Thanks Leon for your quick reply.
Will give it a try and update you.
Regards,
Gopi.
|
|
|
|
|
Hi Leon,
Sorry for late reply. Got time to work on this now only.
Awesome. This one works fine as I expected.
Thanks again.
Regards,
Gopinath.
|
|
|
|
|
Hi
I created a control in my MFC application as follows:
CSpinButtonCtrl m_spin;
m_spin.Create(UDS_HORZ, CRect(0, 0, 50, 50), this, 1011);
m_spin.ShowWindow(1);
which created a spin control with two button with left arrow and right arrow. Now i want to perform some job based on the user clicks on these two buttons. I tried by adding notification message in Message map as follows:
ON_NOTIFY(NM_CLICK, IDC_SPIN1, OnDropDown)
The above message dint called my OnDropDown().
I tried adding ON_WM_HSCROLL(), it worked. The function OnHScroll is getting executed when i click on right or left arrow buttons in spin control.
But what my fear is, in near future i may also add a scroll bars (horiz and veritcal) in my application. That time this may get conflict with my spin control.
So, i am looking for a message which will notify me when left or arrow arrow is invoked on spin control.
|
|
|
|
|
|
Sorry i tried this as follows
ON_NOTIFY_REFLECT(UDN_DELTAPOS,OnSpinContol)
Its throws syntax error and could not find any sample in google to declare the message.
|
|
|
|
|
In what class did you implement it?
Please, post the exact code snippets!
|
|
|
|
|
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY_REFLECT(UDN_DELTAPOS,OnSpinContol)
END_MESSAGE_MAP()
void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{
}
|
|
|
|
|
CMyClass seems to be a parent/owner of the spin control. So there must be ON_NOTIFY macro, not a ON_NOTIFY_REFLECT
|
|
|
|
|
That is for handling the message by the control class itself when having it derived.
To handle the message in the parent do it like you have done already:
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaPos)
|
|
|
|
|
Even tried below one, but no luck.
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnSpinContol)
END_MESSAGE_MAP()
void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{
}
|
|
|
|
|
Sampath579 wrote: Even tried below one, but no luck.
BEGIN_MESSAGE_MAP(CMyClass, CScrollView)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnSpinContol)
END_MESSAGE_MAP()
void CMyClass::OnSpinContol(NMHDR *pNMHDR, LRESULT *pResult)
{
}
1. Define "no luck".
2. Do you pass the correct control ID (IDC_SPIN)?
|
|
|
|
|
Hey Thanks Victor. Its working now.
|
|
|
|
|
It is very probably sourced by the creation of your spin control:
m_spin.Create(UDS_HORZ, CRect(0, 0, 50, 50), this, 1011);
That misses the common window style flags like WS_CHILD | WS_VISIBLE | WS_TABSTOP .
Just out of interest:
Why are you creating your controls manually instead of using resource templates?
With templates the default settings are initially set in the resource editor so that such errors did not occur.
|
|
|
|
|
Hey Thanks..
Finally its working. The very first thing is i am new to MFC and second is i am creating all dynamic windows and controls based on user input.
|
|
|
|
|
|