Pointer Issue in C programming - pointers

I'm getting an error but I don't quite understand why please share any ideas
I think error about the pointer Calibrated *cal;but i don't know how to solve.
I don't have any idea plese share any idea about this problem
#include <stdio.h>
#include "stdint.h"
#include"string.h"
typedef struct{
int16_t Calibration_matrice[3][3];
int16_t average_axis[3];
int16_t bias[3];
int16_t total_average;
float scales[3];
}Calibrated;
void get_CalibratingValues(Calibrated *cal , int16_t x_max , int16_t x_min , int16_t y_max , int16_t y_min , int16_t z_max , int16_t z_min)
{
cal->Calibration_matrice[0][0] = x_min;
cal->Calibration_matrice[0][1] = x_max;
cal->Calibration_matrice[1][0] = y_min;
cal->Calibration_matrice[1][1] = y_max;
cal->Calibration_matrice[2][0] = z_min;
cal->Calibration_matrice[2][1] = z_max;
cal->bias[0] = (cal->Calibration_matrice[0][0] + cal->Calibration_matrice[0][1])/2;
cal->bias[1] = (cal->Calibration_matrice[1][0] + cal->Calibration_matrice[1][1])/2;
cal->bias[2] = (cal->Calibration_matrice[2][0] + cal->Calibration_matrice[2][1])/2;
cal->average_axis[0] = (cal->Calibration_matrice[0][1] - cal->Calibration_matrice[0][0])/2;
cal->average_axis[1] = (cal->Calibration_matrice[1][1] - cal->Calibration_matrice[1][0])/2;
cal->average_axis[2] = (cal->Calibration_matrice[2][1] - cal->Calibration_matrice[2][0])/2;
cal->total_average =((cal->average_axis[0] + cal->average_axis[1] + cal->average_axis[2]) / 3);
cal->scales[0] = (float)(cal->total_average / cal->average_axis[0]);
cal->scales[1] = (float)(cal->total_average / cal->average_axis[1]);
cal->scales[2] = (float)(cal->total_average / cal->average_axis[2]);
}
int main()
{ Calibrated *cal;
get_CalibratingValues(cal,4070,-6610,6440,-4410,4197,-5865);
printf("%d\n",cal->Calibration_matrice[0][0]); // it is not take a value
return 0;
}

Your variable cal is uninitialized. Try:
Calibrated* cal = (Calibrated *) malloc(sizeof(Calibrated));
Don't forget to dispose of it at the end:
free(cal);
Once I do that, I get an output value of -6610.

Related

PCL addpointcloud interface in debug mode normal operation release mode error

I am a newbie in point cloud library and currently I have a problem like the title.I've been debugging in debug mode before, but now I need to release so I'm debugging in release mode for the first time.When I get an error when I load the point cloud using the code below
viewer->removeAllPointClouds();
viewer->removeAllShapes();
viewer->addPointCloud<pcl::PointXYZRGB>(temcloud_ptr,"point cloud");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
viewer->resetCamera();
In viewer->addpointcloud<pcl::PointXYZRGB>(temcloud_ptr,"point cloud");this code,will occur this error :An exception was raised: a read access permission conflict.this is 0xFFFFFFFFFFFFFFDF. and stop here code from xstring screen .
_CONSTEXPR20_CONTAINER bool _Large_string_engaged() const noexcept {
#ifdef __cpp_lib_constexpr_string
if (_STD is_constant_evaluated()) {
return true;
}
#endif // __cpp_lib_constexpr_string
return _BUF_SIZE <= _Myres;
Here's my code
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
auto renderer = vtkSmartPointer<vtkRenderer>::New();
auto renderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
renderWindow->AddRenderer(renderer);
viewer.reset(new pcl::visualization::PCLVisualizer(renderer,
renderWindow,
"viewer",
false));
ui.qvtkwidget->setRenderWindow(viewer->getRenderWindow());
viewer->setupInteractor(ui.qvtkwidget->interactor(),
ui.qvtkwidget->renderWindow());
viewer->setBackgroundColor(0.8941176, 1, 0.9137254);
cloud_ptr.reset(new pcl::PointCloud<PointXYZRGBI>);
cloudrgb_ptr.reset(new pcl::PointCloud<pcl::PointXYZRGB>);
cloudi_ptr.reset(new pcl::PointCloud<pcl::PointXYZI>);
}
void MainWindow::openFile()
{
QString FileName = QFileDialog::getOpenFileName(this,
tr("Open Resource"),
".",
tr("File1(*.las);;File2(*.txt);;File3(*.pcd);;File4(*.ply);;File5(*.obj)"));
if (FileName.isEmpty())
return;
const std::string sstr = FileName.toLocal8Bit();
if (FileName != "")
{
Openfile of;
if (FileName.endsWith("las"))
{
const char* cc_FileName = sstr.c_str();
std::ifstream ifs;
ifs.open(cc_FileName, std::ios::in | std::ios::binary);
liblas::ReaderFactory f;
liblas::Reader reader = f.CreateWithStream(ifs);
liblas::Header const& header = reader.GetHeader();
int pointsNum = header.GetPointRecordsCount();
cloudrgb_ptr->width = pointsNum;
cloudrgb_ptr->height = 1;
cloudrgb_ptr->resize(pointsNum);
for (int i = 0; i < pointsNum; ++i)
{
reader.ReadNextPoint();
const liblas::Point& p = reader.GetPoint();
float px = (float)p.GetX();
float py = (float)p.GetY();
float pz = (float)p.GetZ();
float pi = (float)p.GetIntensity();
uint16_t pr = p.GetColor().GetRed();
uint16_t pg = p.GetColor().GetGreen();
uint16_t pb = p.GetColor().GetBlue();
int r2 = ceil(((float)pr / 65536) * (float)256);
int g2 = ceil(((float)pg / 65536) * (float)256);
int b2 = ceil(((float)pb / 65536) * (float)256);
uint32_t prgb = ((int)r2) << 16 | ((int)g2) << 8 | ((int)b2);
cloudrgb_ptr->points[i].rgb = *reinterpret_cast<float*>(&prgb);
(*cloudrgb_ptr)[i].x = px;
(*cloudrgb_ptr)[i].y = py;
(*cloudrgb_ptr)[i].z = pz;
}
ifs.close();
}
viewer->removeAllPointClouds();
viewer->removeAllShapes();
viewer->addPointCloud<pcl::PointXYZRGB>(cloudrgb_ptr,"point cloud");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
viewer->resetCamera();
ui.qvtkwidget->update();
}
At first I thought the string was not properly initialized so I tried to change the second parameters of addpointcloud such as
const std::string ptcd{ "point cloud" }; const char* arr = "point cloud";
but there is no effect.

expected constructor, destructor, or type conversation before '(' token

I'm new to the world of programming and Arduinos and I am not really sure how to solve this error message. Been researching for answers for quite some time now and I still cannot find an answer as to how to solve this error message. There are error messages on the Arduino IDE and suggestions are also given but I'm not sure how to use those suggestions. I am using an Arduino Pro Micro for this project.
#include <Joystick.h>
//initializing variables
int R2 = 2;
int L3 = 3;
//Define input pins
#define joyX A0
#define joyY A1
#define joyX A2
#define joyY A3
#define joyButton1 2
#define joyButton2 3
//Joystick(Joystick HID ID, Joytstick Type, Button Count, Hat Switch Count, Include X, Include Y, Include Z,
//Include Rx, Include Ry, Include Rudder, Include Throttle, Include Accelerator, Include Break, Include Steering
Joystick_Joystick(0x04, JOYSTICK_TYPE_JOYSTICK, 3, 0, true, true, false, false, false, false, false, false, false, false);
//initializing bool constant
const bool initAutoSendState = true;
//initializing axis
int xAxis_ = 0;
int yAxis_ = 0;
//Set Button Default State
int lastButtonState =0;
int lastButtonState =0;
void setup() {
pinMode(joyButton1, INPUT_PULLUP);
pinMode(joyButton2, INPUT_PULLUP):
Joystick.begin();
}
void loop() {
//Axis Runtime
xAxis_ = analogRead(joyX);
xAxis_ = map (xAxis,0,1023,0,255);
Joystick.setXAxis(xAxis_);
yAxis_ = analogRead(joyY);
yAxis_ = map (yAxis,0,1023,0,255);
Joystick.setYAxis(yAxis_);
//Button State setup
int currentButton1State = !digitalRead(joyButton1);
if (currentButton1State != lastButton1State) {
Joystick.setButton (0, currentButton1State);
lastButton1State = currentButton1State;
}
int currentButton2State = !digitalRead(joyButton2);
if (currentButton2State != lastButton2State) {
Joystick.setButton (0, currentButton2State);
lastButton2State = currentButton2State;
}
//Poll Delay/Debounce
delay(500);
}

Passing data to nlopt in Rcpp?

This is a rather simple question, but I haven't been able to quite find the answer on the web yet.
Wishing my latest attempt, here is latest compiler output:
note: candidate function not viable: no known conversion from 'double (unsigned int, const double *, void *, void )' to 'nlopt_func' (aka 'double ()(unsigned int, const double *, double *, void *)') for 2nd argument
From this error I surmise that I am now wrapping or 'type casting' the data argument correctly and also the parameter vector. The discrepency between the third input, the gradient, confuses me. As I am calling a gradient free optimization routine.
Here is a simple linear regression with a constant and a variable:
#include "RcppArmadillo.h"
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(nloptr)]]
//#include <vector>
#include <nloptrAPI.h>
using namespace arma;
using namespace Rcpp;
typedef struct {
arma::mat data_in;
} *my_func_data;
typedef struct {
double a, b;
} my_theta;
double myfunc(unsigned n, const double *theta, void *grad, void *data){
my_func_data &temp = (my_func_data &) data;
arma::mat data_in = temp->data_in;
my_theta *theta_temp = (my_theta *) theta;
double a = theta_temp->a, b = theta_temp->b;
int Len = arma::size(data_in)[0];
arma::vec Y1 = data_in(span(0, Len-1), 1);
arma::vec Y2 = data_in(span(0, Len-1), 2);
arma::vec res = data_in(span(0, Len-1), 0) - a*Y1 - b*Y2 ;
return sum(res);
}
// [[Rcpp::export]]
void test_nlopt_c() {
arma::mat data_in(10,3);
data_in(span(0,9),0) = arma::regspace(40, 49);
data_in(span(0,9),1) = arma::ones(10);
data_in(span(0,9),2) = arma::regspace(10, 19);
my_func_data &temp = (my_func_data &) data_in;
double lb[2] = { 0, 0,}; /* lower bounds */
nlopt_opt opt;
opt = nlopt_create(NLOPT_LN_NELDERMEAD, 2); /* algorithm and dimensionality */
nlopt_set_lower_bounds(opt, lb);
nlopt_set_min_objective(opt, myfunc, &data_in );
nlopt_set_xtol_rel(opt, 1e-4);
double minf; /* the minimum objective value, upon return */
double x[2] = {0.5, 0.5}; /* some initial guess */
nlopt_result result = nlopt_optimize(opt, x, &minf);
Rcpp::Rcout << "result:" << result;
return;
}
Got it figured out, stupid answer turns out to be correct, just change 'void' to 'double', no clue why. Anyway, the example code needs some improving but it works.
#include "RcppArmadillo.h"
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(nloptr)]]
//#include <vector>
#include <nloptrAPI.h>
using namespace arma;
using namespace Rcpp;
typedef struct {
arma::mat data_in;
} *my_func_data;
typedef struct {
double a, b;
} my_theta;
double myfunc(unsigned n, const double *theta, double *grad, void *data){
my_func_data &temp = (my_func_data &) data;
arma::mat data_in = temp->data_in;
my_theta *theta_temp = (my_theta *) theta;
double a = theta_temp->a, b = theta_temp->b;
int Len = arma::size(data_in)[0];
arma::vec Y1 = data_in(span(0, Len-1), 1);
arma::vec Y2 = data_in(span(0, Len-1), 2);
arma::vec res = data_in(span(0, Len-1), 0) - a*Y1 - b*Y2 ;
return sum(res);
}
// [[Rcpp::export]]
void test_nlopt_c() {
arma::mat data_in(10,3);
data_in(span(0,9),0) = arma::regspace(40, 49);
data_in(span(0,9),1) = arma::ones(10);
data_in(span(0,9),2) = arma::regspace(10, 19);
my_func_data &temp = (my_func_data &) data_in;
double lb[2] = { 0, 0,}; /* lower bounds */
nlopt_opt opt;
opt = nlopt_create(NLOPT_LN_NELDERMEAD, 2); /* algorithm and dimensionality */
nlopt_set_lower_bounds(opt, lb);
nlopt_set_min_objective(opt, myfunc, &data_in );
nlopt_set_xtol_rel(opt, 1e-4);
double minf; /* the minimum objective value, upon return */
double x[2] = {0.5, 0.5}; /* some initial guess */
nlopt_result result = nlopt_optimize(opt, x, &minf);
Rcpp::Rcout << "result:" << result;
return;
}

ili9341 Not Working on STM32f4 discovery

I am testing IlI9341 3.2 TFT LCD on stm32F4-discovery. I wired based on Discovery datasheet. I also read ILI9341 datasheet and went through all registers.
However I get nothing. Also, the LD7, LD5 and LD6 keep on indicating overflow of current. Compiled using Coocox IDE.
The functions SETCURSORPOSITION and FILL are further down.
Here is my code if someone can help me. Thank you.
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_fsmc.h"
#include "LCD.h"
#define LCD_REG (*((volatile unsigned short *) 0x60000000))//address
#define LCD_RAM (*((volatile unsigned short *) 0x60020000))//data
#define MAX_X 320//landscape mode
#define MAX_Y 240//landscape mode
#define ILI9341_PIXEL 76800
#define Green 0x07E0
void LCD_PinsConfiguration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_ResetBits(GPIOD,GPIO_Pin_7);
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource4,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource10,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource11,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource2,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FSMC);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
Delay(5000);
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 0x0F;
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime = 0;
FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 5;
FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration =0;
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision = 0;
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency =0;
FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A;
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1,ENABLE);
}
void LCD_Initialization(void)
{
LCD_PinsConfiguration();
LCD_ILI9341_SendCommand(0x01);
Delay(50000);
LCD_ILI9341_SendCommand(0xcb);
LCD_ILI9341_SendData(0x39);
LCD_ILI9341_SendData(0x2C);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x34);
LCD_ILI9341_SendData(0x02);
LCD_ILI9341_SendCommand(0xcf);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0xC1);
LCD_ILI9341_SendData(0x30);
LCD_ILI9341_SendCommand(0xe8);
LCD_ILI9341_SendData(0x85);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x78);
LCD_ILI9341_SendCommand(0xea);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendCommand(0xed);
LCD_ILI9341_SendData(0x64);
LCD_ILI9341_SendData(0x03);
LCD_ILI9341_SendData(0x12);
LCD_ILI9341_SendData(0x81);
LCD_ILI9341_SendCommand(0xf7);
LCD_ILI9341_SendData(0x20);
LCD_ILI9341_SendCommand(0xc0);
LCD_ILI9341_SendData(0x23);
LCD_ILI9341_SendCommand(0xc1);
LCD_ILI9341_SendData(0x10);
LCD_ILI9341_SendCommand(0xc5);
LCD_ILI9341_SendData(0x3E);
LCD_ILI9341_SendData(0x28);
LCD_ILI9341_SendCommand(0xc7);
LCD_ILI9341_SendData(0x86);
LCD_ILI9341_SendCommand(0x36);
LCD_ILI9341_SendData(0x48);
LCD_ILI9341_SendCommand(0x3a);
LCD_ILI9341_SendData(0x55);
LCD_ILI9341_SendCommand(0xb1);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x18);
LCD_ILI9341_SendCommand(0xb6);
LCD_ILI9341_SendData(0x08);
LCD_ILI9341_SendData(0x82);
LCD_ILI9341_SendData(0x27);
LCD_ILI9341_SendCommand(0xf2);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendCommand(0x2a);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0xEF);
LCD_ILI9341_SendCommand(0x2b);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x01);
LCD_ILI9341_SendData(0x3F);
LCD_ILI9341_SendCommand(0x26);
LCD_ILI9341_SendData(0x01);
LCD_ILI9341_SendCommand(0xe0);
LCD_ILI9341_SendData(0x0F);
LCD_ILI9341_SendData(0x31);
LCD_ILI9341_SendData(0x2B);
LCD_ILI9341_SendData(0x0C);
LCD_ILI9341_SendData(0x0E);
LCD_ILI9341_SendData(0x08);
LCD_ILI9341_SendData(0x4E);
LCD_ILI9341_SendData(0xF1);
LCD_ILI9341_SendData(0x37);
LCD_ILI9341_SendData(0x07);
LCD_ILI9341_SendData(0x10);
LCD_ILI9341_SendData(0x03);
LCD_ILI9341_SendData(0x0E);
LCD_ILI9341_SendData(0x09);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendCommand(0xe1);
LCD_ILI9341_SendData(0x00);
LCD_ILI9341_SendData(0x0E);
LCD_ILI9341_SendData(0x14);
LCD_ILI9341_SendData(0x03);
LCD_ILI9341_SendData(0x11);
LCD_ILI9341_SendData(0x07);
LCD_ILI9341_SendData(0x31);
LCD_ILI9341_SendData(0xC1);
LCD_ILI9341_SendData(0x48);
LCD_ILI9341_SendData(0x08);
LCD_ILI9341_SendData(0x0F);
LCD_ILI9341_SendData(0x0C);
LCD_ILI9341_SendData(0x31);
LCD_ILI9341_SendData(0x36);
LCD_ILI9341_SendData(0x0F);
LCD_ILI9341_SendCommand(0x11);
Delay(50000);
LCD_ILI9341_SendCommand(0x29);
LCD_ILI9341_SendCommand(0x22);
}
void LCD_ILI9341_SendCommand(uint16_t index)
{
LCD_REG = index;
}
void LCD_ILI9341_SendData(uint16_t data)
{
LCD_RAM = data;
}
void LCD_ILI9341_SetCursorPosition(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
LCD_ILI9341_SendCommand(0x2A);
LCD_ILI9341_SendData(x1 >> 8);
LCD_ILI9341_SendData(x1 & 0xFF);
LCD_ILI9341_SendData(x2 >> 8);
LCD_ILI9341_SendData(x2 & 0xFF);
LCD_ILI9341_SendCommand(0x2B);
LCD_ILI9341_SendData(y1 >> 8);
LCD_ILI9341_SendData(y1 & 0xFF);
LCD_ILI9341_SendData(y2 >> 8);
LCD_ILI9341_SendData(y2 & 0xFF);
}
void LCD_ILI9341_Fill(uint16_t color) {
unsigned int n, i, j;
i = color >> 8;
j = color & 0xFF;
LCD_ILI9341_SetCursorPosition(0, 0, MAX_Y - 1, MAX_X - 1);
LCD_ILI9341_SendCommand(0x0022);
for (n = 0; n < ILI9341_PIXEL; n++) {
LCD_ILI9341_SendData(i);
LCD_ILI9341_SendData(j);
}
}
void Delay(__IO uint32_t nCount)
{
while(nCount--)
{
}
}
I am going to answer my own question to make it clear things got solved. But I want to thank the community.
Actually I did few things: I removed GPIOE 2 from configuration block, because it was not being used. I replaced GPIOD to GPIOE in the same block. Inside "LCD_ILI9341_Fill" I changed "LCD_ILI9341_SendCommand(0x0022)" to "LCD_ILI9341_SendCommand(0x002C)". 0x002C is the actual Memory Write address to where you write the data on ili9341. I also connected the LCD RESET pin to the stm32f4 NRST pin. 3V power was connected to LCD LED_A.
Now everything works, I still get wrong colors but I need to make few changes on registers, such as register 36h.
There is a typo there, you're not configuring GPIOE at all.
change the last GPIO_Init() call to
GPIO_Init(GPIOE,&GPIO_InitStructure);
instead of configuring the wrong pins of GPIOD again.
I wired based on Discovery datasheet.
Do you mean the extension board datasheet? Because the Discovery datasheet says nothing about LCD controllers.
LD7, LD5 and LD6 keep on indicating overflow of current
Are you sure? The overcurrent indicator is LD8 (red). You should expect some random lighting up or flickering of LD5, LD6, and LD8, because they are connected to the LCD data lines, but not on LD7.

(Implementation?) error with value noise causing strange artefacts across image

I am doing experiments with terrain generation using heightmaps, and I just wrote a simple value noise. I cannot see anything in my code, but I cannot see anything other than my own stupidity or a floating-point error occuring:
#include
#include <stdlib.h>
#include <math.h>
long jenkins( long a ){
a = (a+0x7ed55d16) + (a>19);
a = (a+0x165667b1) + (a>16);
return a;
}
float random(long x, long y, long seed1, long seed2, long seed3){
long state = jenkins( x ) - jenkins(y);
state = jenkins(state - seed1);
state -= jenkins(state ^ seed2);
state -= jenkins(state - seed2);
state ^= (x*y) - jenkins( (seed1-seed2) ^ seed3 );
float ret = ((float)(state&0xFFFF))/65535.0f;
return ret;
}
float valueNoise( float x, float y, long seed1, long seed2, long seed3 ){
float fx = x-floor(x);
float fy = y-floor(y);
long flx = (long) x-fx;
long fly = (long) y-fy;
fx = fx*fx*(3 - 2*fx);
fy = fy*fy*(3 - 2*fy);
float r00 = random(flx,fly,seed1,seed2,seed3);
float r10 = random(flx+1,fly,seed1,seed2,seed3);
float r01 = random(flx,fly+1,seed1,seed2,seed3);
float r11 = random(flx+1,fly+1,seed1,seed2,seed3);
float i0 = (1-fx)*r00 + fx*r10;
float i1 = (1-fx)*r01 + fx*r11;
return ( (1-fy)*i0 + fy*i1 );
}
void writeOutPGM(char *filename, unsigned char *data){
FILE *file = fopen(filename,"w");
char header[] = "P5 512 512 255\n";
fwrite(header,sizeof(header),1,file);
fwrite(data,262144,1,file);
}
extern float valueNoise( float x, float y, long seed1, long seed2, long seed3 );
int main(){
unsigned char *data = malloc(512*512);
float fx,fy;
int x,y;
long s1 = 123,s2 = 456,s3 = 789;
for( y = 0; y < 512; ++y ){
for( x = 0; x < 512; ++x ){
fx = floor( ((float)x)/10.0f );
fy = floor( ((float)y)/10.0f );
data[x + y*512] = (unsigned char) 255.0f*valueNoise(fx,fy,s1,s2,s3);
}
}
writeOutPGM("noise.pgm",data);
}
I put floor() in to show the lines more clearly, otherwise they are hard to see ( though the noise is still REALLY messed up )
It outputs good noise when I don't divide the x/y. I guess it's either the division or my interpolation. But I am really clueless as to what is happening.
Thanks for any help, Erkling
The error was not with the noise, but rather with the PGM writing code. The file was opened in text-mode on Windows and all UNIX new-lines where converted to the Windows once, causing the weird glitches.

Resources