President Barack Obama will Sunday stare into the stark cell where Nelson Mandela spent years as prisoner of a racist regime, in a visit paying homage to his hero after he left Johannesburg without seeing the ailing icon.

The US leader will fly to Cape Town and then visit the jail on Robben Island, now preserved in searing tribute to the sacrifice and unbreakable strength of the anti-apartheid leader, who now lies critically ill in hospital.

"For me to be able to bring my daughters there and teach them the history of that place and this country ... that's a great privilege and a great honour," said Obama, marvelling at a recent outpouring of love for the ailing icon.

Obama will also build the keynote speech of his three-nation Africa tour at the University of Cape Town around Mandela, and will cite his unifying legacy of a blueprint for a new generation in emerging Africa.

Mandela's illness placed Obama in a tricky political spot, forcing him to balance his desire to push for a new economic relationship with Africa, with the need to properly honour his hero as the world braces for his passing.

On Saturday, Obama and his wife Michelle called Mandela's wife Graca Machel, and the president then privately visited several daughters and grandchildren of Mandela, to offer support and prayers.

But he decided against rolling up in his massive entourage at the Pretoria hospital where the 94-year-old Mandela lies, worried that he would disturb his peace.

"I expressed my hope that Madiba draws peace and comfort from the time that he is spending with loved ones," Obama said in a statement using the 94-year-old Mandela's clan name.

Machel said she drew "strength from the support" from the Obama family.

The example of Mandela, South Africa's first black president, drew Obama into politics for the first time in the 1970s, putting him on a path that would make his own piece of history as America's first black president.

"The struggle here against apartheid, for freedom, Madiba's moral courage, his country's historic transition to a free and democratic nation, has been a personal inspiration to me," Obama said.

"It has been an inspiration to the world," Obama said.

South Africa President Jacob Zuma said after talks with Obama Saturday that Mandela remained in a "critical but stable" condition with a recurring lung infection.

And he said that Obama and Mandela were "bound by history" after breaking racial barriers to rise to power.

"You both carry the dreams of millions of people in Africa," Zuma, who also spent 10 years on Robben island, told Obama.

South Africa's last apartheid president FW de Klerk meanwhile cut short a visit to Europe because of the ailing health of his co-Nobel prize winner.

Obama's warm welcome was not universal. Riot police fired rubber bullets and stun grenades at around 300 hundred anti-Obama protesters in the township of Soweto, once a flashpoint in the anti-apartheid struggle.

Many Soweto residents, however, see Obama, the son of a white American mother and a Kenyan father, as a "fellow African".

"To me, Madiba represents an older and perhaps more traditional generation of black leaders, while Obama represents the new generation," Tshepo Mofokeng, 43, told AFP. "I'm sure he will be welcomed here as an African."

Not far from the protest, Obama held a town hall style meeting with 600 young African leaders with a video link up to young people in Nigeria, Uganda and Kenya.

Africa "is in your hands" Obama told the youngsters and urged them to use Mandela as a model for political leadership.

"Think about 27 years in prison ... there were dark moments that tested his faith in humanity, but he refused to give up."

Obama's tour of Senegal, South Africa and Tanzania is aimed at changing perceptions that he has neglected Africa since his election in 2008, while also countering China's growing economic influence in the resource-rich continent.

On Sunday, a day ringing with political symbolism, the US president will be walking in revered footsteps when he gives the speech at the University of Cape Town -- those of slain US presidential candidate Robert Kennedy.

RFK gave his famed "ripple of hope" speech at the same venue in 1966, which was a call for non-violent change and equality, at a time when America was still dealing with the racial discrimination which stained its own history.

Kennedy gave the speech only two years after Mandela was sentenced to life in prison and sent to Robben Island.

"Given the difficult moment we are in with his current health, it makes it that much more profound and significant with the president being here in South Africa," said Ben Rhodes, a deputy US national security advisor.

Mandela, once branded a terrorist by the United States and Britain, was freed in 1990 and became president after the first fully democratic elections in 1994.

Also Sunday, Obama, accompanied on his tour by his wife and daughters Malia and Sasha, will visit an HIV/AIDS Center named for another icon of South Africa's emancipation struggle, Archbishop Desmond Tutu.

South African President Jacob Zuma and US President Barack Obama toast each other alongside Zuma's wife, Thobeka Zuma, during an official dinner at the Presidential Guest House in Pretoria, June 29, 2013. Obama will Sunday stare into the cell where Nelson Mandela spent years as prisoner, in a visit paying homage to his hero after he left Johannesburg without seeing the ailing icon./AFP