Hello
First it is great to see how Great Cow has come on so well in the past few years and thanks to everyone who has contributed to its success.
I have inherited some MPLAB C Source Firmware for an AD5421 16-Bit, Serial Input, Loop-Powered, 4 mA to 20 mA DAC which I would like to convert to Great Cow. (I am not a great fan of MPLAB its IDE drives me wild).
I have worked out a lot of the code and using an LCD display and stubbing and can see the right bytes of information doing the right things my issue is on the SPI side which I have not used before in either GC or MPLAB.
I am pretty sure the SPI Connections are correct including the CS select line, it runs in Master Mode.
My questions are :
1) MPLAB has the SPI set to SPI Mode 1, Input data sampled at Middle; Clock Edge idle to active; what is the
GC equivalent setting?
2) MPLAB has the SPI Clock set to 125kHz; what is the GC equivalent setting? and does this matter too much
on SPI?
3) How do I convert the SPI part of the code shown below to GC ?
unsigned long AD5421_GetRegisterValue(unsigned char regAddress)
{
unsigned char data[5] = {0x03, 0x00, 0x00, 0x00, 0x00};
unsigned long receivedData = 0x00;
data[0] = regAddress | AD5421_READ; ‘This is correct in the GC version
**‘This is the area where I am stuck **
ADI_CS_LOW;
SPI_Exchange8bitBuffer(data,3,0); ‘This is the area where I am stuck
ADI_CS_HIGH;
ADI_CS_LOW;
SPI_Exchange8bitBuffer(0,3,data);
ADI_CS_HIGH;
receivedData+=(data[1]<<8); ‘This is correct in the GC versionreceivedData+=(data[2]<<0); ‘This is correct in the GC versionreturnreceivedData; ‘I have manged to pass this OK in GC
}
I have tried looking at the Data Sheet and help but for some reason cannot get my head round it.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK, Here goes. I would not use the approach above - a clean start and the data sheet is always best..
This is rather simple device. Use the SPI calls within Great Cow BASIC, you be able use one of the GLCD libraries as resource if you wiah.
Start with glcd_ILI9341.h ( in the include folder). Extract the SPI write commands noting support for hardware and software SPI, Also, the ILI9341 iniit has the correct initialisation process for the ports and the hardware SPI.
Hello
First it is great to see how Great Cow has come on so well in the past few years and thanks to everyone who has contributed to its success.
I have inherited some MPLAB C Source Firmware for an AD5421 16-Bit, Serial Input, Loop-Powered, 4 mA to 20 mA DAC which I would like to convert to Great Cow. (I am not a great fan of MPLAB its IDE drives me wild).
I have worked out a lot of the code and using an LCD display and stubbing and can see the right bytes of information doing the right things my issue is on the SPI side which I have not used before in either GC or MPLAB.
I am pretty sure the SPI Connections are correct including the CS select line, it runs in Master Mode.
My questions are :
1) MPLAB has the SPI set to SPI Mode 1, Input data sampled at Middle; Clock Edge idle to active; what is the
GC equivalent setting?
2) MPLAB has the SPI Clock set to 125kHz; what is the GC equivalent setting? and does this matter too much
on SPI?
3) How do I convert the SPI part of the code shown below to GC ?
unsigned long AD5421_GetRegisterValue(unsigned char regAddress)
{
unsigned char data[5] = {0x03, 0x00, 0x00, 0x00, 0x00};
unsigned long receivedData = 0x00;
data[0] = regAddress | AD5421_READ; ‘This is correct in the GC version
**‘This is the area where I am stuck **
ADI_CS_LOW;
SPI_Exchange8bitBuffer(data,3,0); ‘This is the area where I am stuck
ADI_CS_HIGH;
ADI_CS_LOW;
SPI_Exchange8bitBuffer(0,3,data);
ADI_CS_HIGH;
}
I have tried looking at the Data Sheet and help but for some reason cannot get my head round it.
Thanks
OK, Here goes. I would not use the approach above - a clean start and the data sheet is always best..
This is rather simple device. Use the SPI calls within Great Cow BASIC, you be able use one of the GLCD libraries as resource if you wiah.
Start with glcd_ILI9341.h ( in the include folder). Extract the SPI write commands noting support for hardware and software SPI, Also, the ILI9341 iniit has the correct initialisation process for the ports and the hardware SPI.
The pop over and get this zip . https://wiki.analog.com/_media/resources/tools-software/uc-drivers/renesas/ad5421_generic.zip This is a good generic library. Move the constants from the .h to your code as constant.
This should be a nice library - ask more questions as needed.